[squeak-dev] The Trunk: Collections-ul.679.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue Mar 8 20:06:32 UTC 2016
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.679.mcz
==================== Summary ====================
Name: Collections-ul.679
Author: ul
Time: 8 March 2016, 5:24:30.010047 pm
UUID: 9f4b6193-4632-48c7-a99f-ee37923bf28b
Ancestors: Collections-eem.678
#occurrencesOf: revamp:
- optimized Bag's implementation
- added optimized versions to ArrayedCollection, String and ByteArray
=============== Diff against Collections-eem.678 ===============
Item was added:
+ ----- Method: ArrayedCollection>>occurrencesOf: (in category 'testing') -----
+ occurrencesOf: anObject
+ "Answer how many of the receiver's elements are equal to anObject. Optimized version."
+
+ | tally |
+ tally := 0.
+ 1 to: self size do: [ :index |
+ (self at: index) = anObject ifTrue: [ tally := tally + 1 ] ].
+ ^tally!
Item was changed:
----- Method: Bag>>occurrencesOf: (in category 'testing') -----
+ occurrencesOf: anObject
+ "Answer how many of the receiver's elements are equal to anObject. Optimized version."
- occurrencesOf: anObject
- "Refer to the comment in Collection|occurrencesOf:."
+ ^contents at: anObject ifAbsent: 0!
- (self includes: anObject)
- ifTrue: [^contents at: anObject]
- ifFalse: [^0]!
Item was added:
+ ----- Method: ByteArray>>occurrencesOf: (in category 'as yet unclassified') -----
+ occurrencesOf: anObject
+ "Answer how many of the receiver's elements are equal to anObject. Optimized version."
+
+ | tally |
+ anObject isInteger ifFalse: [ ^0 ].
+ anObject negative ifTrue: [ ^0 ].
+ anObject > 255 ifTrue: [ ^0 ].
+ tally := 0.
+ 1 to: self size do: [ :index |
+ (self at: index) = anObject ifTrue: [ tally := tally + 1 ] ].
+ ^tally!
Item was added:
+ ----- Method: String>>occurrencesOf: (in category 'testing') -----
+ occurrencesOf: anObject
+ "Answer how many of the receiver's elements are equal to anObject. Optimized version."
+
+ | tally |
+ anObject isCharacter ifFalse: [ ^0 ].
+ tally := 0.
+ 1 to: self size do: [ :index |
+ (self at: index) == anObject ifTrue: [ tally := tally + 1 ] ].
+ ^tally!
More information about the Squeak-dev
mailing list
|