[ENH][FIX] (fulltext) Faster String equality.

Scott A Crosby crosby at qwes.math.cmu.edu
Sat Apr 13 11:38:54 UTC 2002


A quicky:

``
'From Squeak3.2alpha of 11 October 2001 [latest update: #4646] on 13 April
2002
at 7:25:09 am'!

!String methodsFor: 'arithmetic' stamp: 'sac 4/13/2002 07:24'!
= aString
        "Answer whether the receiver sorts equally as aString.
        The collation order is simple ascii (with case differences)."

        aString species == String ifFalse: [
                aString isText ifTrue: [^ self = aString string].
                ^ false].
        self == aString ifTrue: [^ true].
        ^ (self compare: self with: aString collated: AsciiOrder) = 2! !
''

When working on a larger writeup on fulltext, I realized that having an
additional check of:

        self == aString ifTrue: [^ true].

Can save doing a slow string comparison. This is especially apparent in
the fulltext indexing in the case where one is indexing Strings.. If the
same term occurs in a string more than once, the different ones will be
#== each other and we can save the slow String>>=

As an interesting aside, this sort of check should be added to any other
class that going to be fulltextindexed, when #= is slow.

(If you know of such classes, it may be a good idea to make similar
changes.)


Scott

-------------- next part --------------
'From Squeak3.2alpha of 11 October 2001 [latest update: #4646] on 13 April 2002 at 7:25:09 am'!

!String methodsFor: 'arithmetic' stamp: 'sac 4/13/2002 07:24'!
= aString 
	"Answer whether the receiver sorts equally as aString.
	The collation order is simple ascii (with case differences)."

	aString species == String ifFalse: [
		aString isText ifTrue: [^ self = aString string].
		^ false].
	self == aString ifTrue: [^ true].
	^ (self compare: self with: aString collated: AsciiOrder) = 2! !



More information about the Squeak-dev mailing list