On Mon, 26 Dec 2011, commits@source.squeak.org wrote:
Chris Muller uploaded a new version of Collections to project The Trunk: http://source.squeak.org/trunk/Collections-cmm.466.mcz
==================== Summary ====================
Name: Collections-cmm.466 Author: cmm Time: 29 November 2011, 9:26:57.286 pm UUID: 3a05d4e5-8c72-4b50-85a2-40eba66bc358 Ancestors: Collections-ul.465
Allow subclasses to override the internal 'array' of a HashedCollection.
Why is #arrayType on the class side? What are the practical alternatives of Array as #arrayType?
Levente
=============== Diff against Collections-ul.465 ===============
Item was added:
- ----- Method: HashedCollection class>>arrayType (in category 'private') -----
- arrayType
- ^ Array!
Item was changed: ----- Method: HashedCollection>>growTo: (in category 'private') ----- growTo: anInteger "Grow the elements array and reinsert the old elements"
| oldElements | oldElements := array.
- array := self class arrayType new: anInteger.
- array := Array new: anInteger. self noCheckNoGrowFillFrom: oldElements!
Item was changed: ----- Method: HashedCollection>>initialize: (in category 'private') ----- initialize: n "Initialize array to an array size of n"
- array := self class arrayType new: n.
- array := Array new: n. tally := 0!
Why is #arrayType on the class side?
I must admit I wrung my hands about this decision -- the answer is "consistency" with OrderedCollection, which needs its #arrayType on the class side for the case where the user wants to pre-allocate extra slots. In that case, the initial 'array' is allocated in the class-side constructor (see OrderedCollection class>>#new:).
However, HashedCollection doesn't do it that way, so it probably _could_ have gone on the instance-side. Still, I thought there was no harm in being consistent with OC.
What are the practical alternatives of Array as #arrayType?
To have a compactable Array class. WbArray is a subclass of Array included with Magma that can, therefore, be used with the WriteBarrier. WbOrderedCollection, WbSet and WbDictionary follow by simply overriding their #arrayType which, in at least the app I'm measuring, affords a 20X improvement in application performance.
- Chris
squeak-dev@lists.squeakfoundation.org