[squeak-dev] The Trunk: Collections-ul.685.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Apr 3 02:33:19 UTC 2016


Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.685.mcz

==================== Summary ====================

Name: Collections-ul.685
Author: ul
Time: 3 April 2016, 3:21:51.035808 am
UUID: db8fd391-2306-4ccc-87d5-b5dee96a78ab
Ancestors: Collections-eem.684

Use Spur's new character comparison abilities in some String methods.

=============== Diff against Collections-eem.684 ===============

Item was changed:
  ----- Method: ByteString>>findSubstring:in:startingAt:matchTable: (in category 'comparing') -----
  findSubstring: key in: body startingAt: start matchTable: matchTable
  	"Answer the index in the string body at which the substring key first occurs, at or beyond start.  The match is determined using matchTable, which can be used to effect, eg, case-insensitive matches.  If no match is found, zero will be returned.
  
  	The algorithm below is not optimum -- it is intended to be translated to C which will go so fast that it wont matter."
  	| index |
  	<primitive: 'primitiveFindSubstring' module: 'MiscPrimitivePlugin'>
  	<var: #key declareC: 'unsigned char *key'>
  	<var: #body declareC: 'unsigned char *body'>
  	<var: #matchTable declareC: 'unsigned char *matchTable'>
  
  	key size = 0 ifTrue: [^ 0].
+ 	matchTable ifNil: [
+ 		start to: body size - key size + 1 do: [ :startIndex |
+ 			index := 0.
+ 			[ (body at: startIndex + index) == (key at: (index := index + 1)) ] whileTrue: [
+ 				index = key size ifTrue: [ ^startIndex ] ] ].
+ 		^0 ].
  	(start max: 1) to: body size - key size + 1 do:
  		[:startIndex |
  		index := 1.
  			[(matchTable at: (body at: startIndex+index-1) asciiValue + 1)
  				= (matchTable at: (key at: index) asciiValue + 1)]
  				whileTrue:
  				[index = key size ifTrue: [^ startIndex].
  				index := index+1]].
  	^ 0
  "
  ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 1 matchTable: CaseSensitiveOrder 1
  ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 2 matchTable: CaseSensitiveOrder 7
  ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 8 matchTable: CaseSensitiveOrder 0
  ' ' findSubstring: 'abc' in: 'abcdefABcd' startingAt: 2 matchTable: CaseSensitiveOrder 0
  ' ' findSubstring: 'abc' in: 'abcdefABcd' startingAt: 2 matchTable: CaseInsensitiveOrder 7
  "!

Item was changed:
  ----- Method: String>>beginsWith: (in category 'testing') -----
  beginsWith: sequence
  	"Answer true if the receiver starts with the argument collection. The comparison is case-sensitive. Overridden for better performance."
  
+ 	| index sequenceSize |
- 	| sequenceSize |
  	sequence isString ifFalse: [ ^super beginsWith: sequence ].
+ 	((sequenceSize := sequence size) = 0 or: [ self size < sequenceSize ]) ifTrue: [ ^false ].
+ 	index := 0.
+ 	[ (index := index + 1) <= sequenceSize ] whileTrue: [
+ 		(sequence at: index) == (self at: index) ifFalse: [ ^false ] ].
- 	((sequenceSize := sequence size) = 0 or: [ self size < sequence size ]) ifTrue: [ ^false ].
- 	1 to: sequenceSize do: [ :index |
- 		(sequence basicAt: index) = (self basicAt: index) ifFalse: [ ^false ] ].
  	^true!

Item was changed:
  ----- Method: String>>endsWith: (in category 'testing') -----
  endsWith: sequence
  	"Answer true if the receiver ends with the argument collection. The comparison is case-sensitive."
  	
+ 	| index sequenceSize offset |
- 	| sequenceSize offset |
  	sequence isString ifFalse: [ ^ super endsWith: sequence ].
+ 	((sequenceSize := sequence size) = 0 or: [ (offset := self size - sequenceSize) < 0 ]) ifTrue: [ ^false ].
+ 	index := 0.
+ 	[ (index := index + 1) <= sequenceSize ] whileTrue: [
+ 		(sequence at: index) == (self at: index + offset) ifFalse: [ ^false ] ].
- 	((sequenceSize := sequence size) = 0 or: [ (offset := self size - sequence size) < 0 ]) ifTrue: [ ^false ].
- 	1 to: sequenceSize do: [ :index |
- 		(sequence basicAt: index) = (self basicAt: index + offset) ifFalse: [ ^false ] ].
  	^true!

Item was changed:
  ----- Method: String>>findSubstring:in:startingAt:matchTable: (in category 'accessing') -----
  findSubstring: key in: body startingAt: start matchTable: matchTable
  	"Answer the index in the string body at which the substring key first occurs, at or beyond start.  The match is determined using matchTable, which can be used to effect, eg, case-insensitive matches.  If no match is found, zero will be returned."
- 	| index c1 c2 |
- 	matchTable == nil ifTrue: [
- 		key size = 0 ifTrue: [^ 0].
- 		start to: body size - key size + 1 do:
- 			[:startIndex |
- 			index := 1.
- 				[(body at: startIndex+index-1)
- 					= (key at: index)]
- 					whileTrue:
- 					[index = key size ifTrue: [^ startIndex].
- 					index := index+1]].
- 		^ 0
- 	].
  
+ 	| index c1 c2 keySize matchTableSize |
+ 	(keySize := key size) = 0 ifTrue: [ ^0 ].
+ 	matchTable ifNil: [
+ 		start to: body size - key size + 1 do: [ :startIndex |
+ 			index := 0.
+ 			[ (body at: startIndex + index) == (key at: (index := index + 1)) ] whileTrue: [
+ 				index = keySize ifTrue: [ ^startIndex ] ] ].
+ 		^0 ].
+ 	matchTableSize := matchTable size.
+ 	start to: body size - key size + 1 do: [ :startIndex |
+ 		index := 0.
+ 		[
+ 			(c1 := (body at: startIndex + index) asInteger + 1) <= matchTableSize ifTrue: [
+ 				c1 := matchTable at: c1 ].
+ 			(c2 := (key at: (index := index + 1)) asInteger + 1) <= matchTableSize ifTrue: [
+ 				c2 := matchTable at: c2 ].
+ 			c1 = c2 ]
+ 			whileTrue: [
+ 				index = keySize ifTrue: [ ^startIndex ] ] ].
+ 	^0!
- 	key size = 0 ifTrue: [^ 0].
- 	start to: body size - key size + 1 do:
- 		[:startIndex |
- 		index := 1.
- 		[c1 := body at: startIndex+index-1.
- 		c2 := key at: index.
- 		((c1 leadingChar = 0 and: [ c1 asciiValue < matchTable size ]) 
- 			ifTrue: [ matchTable at: c1 asciiValue + 1 ]
- 			ifFalse: [ c1 asciiValue + 1 ]) = 
- 			((c2 leadingChar = 0 and: [ c2 asciiValue < matchTable size ])
- 				ifTrue: [ matchTable at: c2 asciiValue + 1 ]
- 				ifFalse: [c2 asciiValue + 1 ]) ]
- 			whileTrue:
- 				[index = key size ifTrue: [^ startIndex].
- 				index := index+1]].
- 	^ 0!



More information about the Squeak-dev mailing list