[Pkg] The Trunk: Collections-ul.753.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Apr 27 11:08:40 UTC 2017


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

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

Name: Collections-ul.753
Author: ul
Time: 27 April 2017, 12:08:58.187065 am
UUID: 9c169c46-7fca-4bd9-a1d2-12ebd52b93a8
Ancestors: Collections-nice.752

- minor tweaks for String class >> #compare:with:collated: and String >> #findSubstring:in:startingAt:matchTable:

=============== Diff against Collections-nice.752 ===============

Item was changed:
  ----- Method: String class>>compare:with:collated: (in category 'primitives') -----
  compare: string1 with: string2 collated: order
  	"Return 1, 2 or 3, if string1 is <, =, or > string2, with the collating order of characters given by the order array."
  
+ 	| c1 c2 length1 length2 |
+ 	length1 := string1 size.
+ 	length2 := string2 size.
+ 	(order == nil or: [ order == AsciiOrder ]) ifTrue: [ "AsciiOrder is the identity function"
+ 		1 to: (length1 min: length2) do: [ :i |
+ 			(c1 := string1 basicAt: i) = (c2 := string2 basicAt: i) ifFalse: [
+ 				c1 < c2
+ 					ifTrue: [ ^1 ]
+ 					ifFalse: [ ^3 ] ] ].
+ 		length1 = length2 ifTrue: [ ^2 ].
+ 		length1 < length2
+ 			ifTrue: [ ^1 ]
+ 			ifFalse: [ ^3 ] ].
+ 	1 to: (length1 min: length2) do: [ :i |
+ 		(c1 := string1 basicAt: i) < 256 ifTrue: [ c1 := order at: c1 + 1 ].
+ 		(c2 := string2 basicAt: i) < 256 ifTrue: [ c2 := order at: c2 + 1 ].
+ 		c1 = c2 ifFalse:[
+ 			c1 < c2 
+ 				ifTrue: [ ^1 ]
+ 				ifFalse: [ ^3 ] ] ].
+ 	length1 = length2 ifTrue: [ ^2 ].
+ 	length1 < length2
+ 		ifTrue: [ ^1 ]
+ 		ifFalse: [ ^3 ].!
- 	| len1 len2 c1 c2 |
- 	order == nil ifTrue: [
- 		len1 := string1 size.
- 		len2 := string2 size.
- 		1 to: (len1 min: len2) do:[:i |
- 			c1 := string1 basicAt: i.
- 			c2 := string2 basicAt: i.
- 			c1 = c2 ifFalse: [c1 < c2 ifTrue: [^ 1] ifFalse: [^ 3]].
- 		].
- 		len1 = len2 ifTrue: [^ 2].
- 		len1 < len2 ifTrue: [^ 1] ifFalse: [^ 3].
- 	].
- 	len1 := string1 size.
- 	len2 := string2 size.
- 	1 to: (len1 min: len2) do:[:i |
- 		c1 := string1 basicAt: i.
- 		c2 := string2 basicAt: i.
- 		c1 < 256 ifTrue: [c1 := order at: c1 + 1].
- 		c2 < 256 ifTrue: [c2 := order at: c2 + 1].
- 		c1 = c2 ifFalse:[c1 < c2 ifTrue: [^ 1] ifFalse: [^ 3]].
- 	].
- 	len1 = len2 ifTrue: [^ 2].
- 	len1 < len2 ifTrue: [^ 1] ifFalse: [^ 3].
- !

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 keySize matchTableSize |
  	(keySize := key size) = 0 ifTrue: [ ^0 ].
  	matchTable ifNil: [
+ 		start to: body size - keySize + 1 do: [ :startIndex |
- 		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 - keySize + 1 do: [ :startIndex |
- 	start to: body size - key size + 1 do: [ :startIndex |
  		index := 0.
  		[
+ 			(c1 := (body basicAt: startIndex + index) + 1) <= matchTableSize ifTrue: [
- 			(c1 := (body at: startIndex + index) asInteger + 1) <= matchTableSize ifTrue: [
  				c1 := matchTable at: c1 ].
+ 			(c2 := (key basicAt: (index := index + 1)) + 1) <= matchTableSize ifTrue: [
- 			(c2 := (key at: (index := index + 1)) asInteger + 1) <= matchTableSize ifTrue: [
  				c2 := matchTable at: c2 ].
  			c1 = c2 ]
  			whileTrue: [
  				index = keySize ifTrue: [ ^startIndex ] ] ].
  	^0!



More information about the Packages mailing list