[squeak-dev] The Trunk: Collections-ul.729.mcz
commits at source.squeak.org
commits at source.squeak.org
Sun Dec 25 15:19:45 UTC 2016
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.729.mcz
==================== Summary ====================
Name: Collections-ul.729
Author: ul
Time: 25 December 2016, 4:16:33.349302 pm
UUID: dedb0ac7-ea11-42b9-8a91-2839a52866c7
Ancestors: Collections-nice.728
- minor OrderedCollection optimizations
=============== Diff against Collections-nice.728 ===============
Item was changed:
----- Method: OrderedCollection>>asArray (in category 'converting') -----
asArray
"Overriden for speed"
+ | result size |
+ result := Array new: (size := self size).
- | result |
- result := Array new: self size.
result
replaceFrom: 1
+ to: size
- to: result size
with: array
startingAt: firstIndex.
^result!
Item was changed:
----- Method: OrderedCollection>>makeRoomAtFirst (in category 'private') -----
makeRoomAtFirst
"Make some empty slots at the front of the array. If we have more than 50% free space, then just move the elements, so that the first 50% of the slots are free, otherwise add new free slots to the front by growing. Precondition: firstIndex = 1"
+ | tally newFirstIndex newLastIndex capacity |
- | tally newFirstIndex newLastIndex |
tally := self size.
+ capacity := array size.
+ tally * 2 >= capacity ifTrue: [ ^self growAtFirst ].
+ tally = 0 ifTrue: [ ^self resetTo: capacity + 1 ].
+ newFirstIndex := capacity // 2 + 1.
- tally * 2 >= array size ifTrue: [ ^self growAtFirst ].
- tally = 0 ifTrue: [ ^self resetTo: array size + 1 ].
- newFirstIndex := array size // 2 + 1.
newLastIndex := newFirstIndex - firstIndex + lastIndex.
0 to: tally - 1 do: [ :offset |
array at: newLastIndex - offset put: (array at: lastIndex - offset) ].
array from: firstIndex to: newFirstIndex - 1 put: nil.
firstIndex := newFirstIndex.
lastIndex := newLastIndex!
Item was added:
+ ----- Method: OrderedCollection>>replace: (in category 'enumerating') -----
+ replace: aBlock
+ "Evaluate aBlock with each of my elements as the argument. Collect the resulting values into myself.
+ Override superclass in order to work on the internal array directly."
+
+ firstIndex to: lastIndex do: [ :index |
+ array at: index put: (aBlock value: (array at: index)) ]!
Item was changed:
----- Method: OrderedCollection>>with:collect: (in category 'enumerating') -----
with: otherCollection collect: twoArgBlock
"Collect and return the result of evaluating twoArgBlock with
corresponding elements from this collection and otherCollection."
+
+ | result offset size |
+ (size := self size) = otherCollection size ifFalse: [ self error: 'otherCollection must be the same size' ].
+ result := self species new: size.
+ offset := 1 - firstIndex.
+ firstIndex to: lastIndex do: [ :index |
+ result addLast: (
+ twoArgBlock
+ value: (array at: index)
+ value: (otherCollection at: index + offset)) ].
+ ^result!
- | result |
- otherCollection size = self size ifFalse: [self error: 'otherCollection must be the same size'].
- result := self species new: self size.
- 1 to: self size do:
- [:index | result addLast: (twoArgBlock value: (self at: index)
- value: (otherCollection at: index))].
- ^ result!
Item was changed:
----- Method: OrderedCollection>>withIndexCollect: (in category 'enumerating') -----
withIndexCollect: elementAndIndexBlock
"Just like with:collect: except that the iteration index supplies the second argument to the block. Override superclass in order to use addLast:, not at:put:."
+ | newCollection offset |
- | newCollection |
newCollection := self species new: self size.
+ offset := 1 - firstIndex.
firstIndex to: lastIndex do:
[:index |
newCollection addLast: (elementAndIndexBlock
value: (array at: index)
+ value: index + offset) ].
- value: index - firstIndex + 1)].
^ newCollection!
More information about the Squeak-dev
mailing list
|