The Trunk: Collections-ul.380.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-ul.380.mcz

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

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

Name: Collections-ul.380
Author: ul
Time: 12 September 2010, 4:14:05.604 am
UUID: 0b9b1e03-48cd-4140-9a41-c4e521e9ae24
Ancestors: Collections-ul.379

- faster non-primitive String "primitives" by using #basicAt: instead of #at: + #asInteger/#asciiValue
- revert to #to:do: instead of a #whileTrue: in #indexOfAscii:inString:startingAt: , because that's also inlined even if the receiver type is unknown

=============== Diff against Collections-ul.379 ===============

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."
 
  | 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 := (string1 at: i) asInteger.
- c2 := (string2 at: i) asInteger.
  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 := (string1 at: i) asInteger.
- c2 := (string2 at: i) asInteger.
  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 class>>findFirstInString:inSet:startingAt: (in category 'primitives') -----
  findFirstInString: aString inSet: inclusionMap startingAt: start
  "Trivial, non-primitive version"
 
  | i stringSize ascii more |
  inclusionMap size ~= 256 ifTrue: [^ 0].
  stringSize := aString size.
  more := true.
  i := start - 1.
  [more and: [(i := i + 1) <= stringSize]] whileTrue: [
+ ascii := aString basicAt: i.
- ascii := (aString at: i) asciiValue.
  more := ascii < 256 ifTrue: [(inclusionMap at: ascii + 1) = 0] ifFalse: [true].
  ].
 
  i > stringSize ifTrue: [^ 0].
  ^ i!

Item was changed:
  ----- Method: String class>>indexOfAscii:inString:startingAt: (in category 'primitives') -----
  indexOfAscii: anInteger inString: aString startingAt: start
  "Trivial, non-primitive version"
 
+ start to: aString size do: [ :index |
- | index endIndex |
- endIndex := aString size.
- index := start - 1.
- [ (index := index + 1) <= endIndex ] whileTrue: [
  (aString basicAt: index) = anInteger ifTrue: [ ^index ] ].
  ^0
  !

Item was changed:
  ----- Method: String class>>stringHash:initialHash: (in category 'primitives') -----
  stringHash: aString initialHash: speciesHash
+
  | stringSize hash low |
  stringSize := aString size.
+ hash := speciesHash bitAnd: 16r0FFFFFFF.
+ 1 to: stringSize do: [ :pos |
+ hash := hash + (aString basicAt: pos).
- hash := speciesHash bitAnd: 16rFFFFFFF.
- 1 to: stringSize do: [:pos |
- hash := hash + (aString at: pos) asInteger.
  "Begin hashMultiply"
  low := hash bitAnd: 16383.
+ hash := (16r260D * low + ((16r260D * (hash // 16384) + (16r0065 * low) bitAnd: 16383) * 16384)) bitAnd: 16r0FFFFFFF ].
+ ^hash.
+
+
- hash := (16r260D * low + ((16r260D * (hash bitShift: -14) + (16r0065 * low) bitAnd: 16383) * 16384)) bitAnd: 16r0FFFFFFF.
- ].
- ^ hash.
  !

Item was changed:
  ----- Method: String class>>translate:from:to:table: (in category 'primitives') -----
  translate: aString from: start  to: stop  table: table
  "Trivial, non-primitive version"
+
+ start to: stop do: [ :i |
+ | char |
+ (char := aString basicAt: i) < 256 ifTrue: [
+ aString at: i put: (table at: char+1) ] ].
- | char |
- start to: stop do: [:i |
- char := (aString at: i) asInteger.
- char < 256 ifTrue: [aString at: i put: (table at: char+1)].
- ].
  !