[squeak-dev] The Trunk: Collections-ul.427.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Thu Feb 24 21:24:46 UTC 2011


Of course, these are hardly whishable features, and I think it is good
to get rid of #asInteger, but I was intrigued :

(Array new: 100 withAll: 0) asOrderedCollection at: $A put: 1; at:
'2+10' put: 3; yourself.
-> try it by yourself before applying the change

(OrderedCollection with: $a with: $b) at: 9/4 put: $c; yourself.
before change -> #($a $c), after change -> error

Though #($a $b) at: 9/4 still "works"

(OrderedCollection with: $a with: $b) at: 7/4 put: $c; yourself.
still "works"  -> #($c $b)

because Object>>#at:put: still use #asInteger... (only in case of a Number).
I wonder why we shall let Object interpret our intentions (or bugs)...
Isn't it time to change it too ?

Nicolas

2011/2/24  <commits at source.squeak.org>:
> Levente Uzonyi uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-ul.427.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ul.427
> Author: ul
> Time: 24 February 2011, 2:42:16.909 pm
> UUID: 40a987b8-4024-9e45-bdb9-ac0b0b888ad2
> Ancestors: Collections-ul.426
>
> OrderedCollection tweaks:
> - optimized (bytecode + stack usage) #addFirst: and #addLast:
> - removed the #asInteger send from #at:put:, because no other operations use it
> - recategorized and commented #reset and #resetTo:
>
> =============== Diff against Collections-ul.426 ===============
>
> Item was changed:
>  ----- Method: OrderedCollection>>addFirst: (in category 'adding') -----
>  addFirst: newObject
>        "Add newObject to the beginning of the receiver. Answer newObject."
>
> +       firstIndex = 1 ifTrue: [ self makeRoomAtFirst ].
> +       ^array at: (firstIndex := firstIndex - 1) put: newObject!
> -       firstIndex = 1 ifTrue: [self makeRoomAtFirst].
> -       firstIndex := firstIndex - 1.
> -       array at: firstIndex put: newObject.
> -       ^ newObject!
>
> Item was changed:
>  ----- Method: OrderedCollection>>addLast: (in category 'adding') -----
>  addLast: newObject
>        "Add newObject to the end of the receiver. Answer newObject."
>
> +       array size = lastIndex ifTrue: [ self makeRoomAtLast ].
> +       ^array at: (lastIndex := lastIndex + 1) put: newObject!
> -       lastIndex = array size ifTrue: [self makeRoomAtLast].
> -       lastIndex := lastIndex + 1.
> -       array at: lastIndex put: newObject.
> -       ^ newObject!
>
> Item was changed:
>  ----- Method: OrderedCollection>>at:put: (in category 'accessing') -----
>  at: anInteger put: anObject
>        "Put anObject at element index anInteger. at:put: cannot be used to
>        append, front or back, to an ordered collection; it is used by a
>        knowledgeable client to replace an element."
>
> +       (anInteger < 1 or: [anInteger + firstIndex - 1 > lastIndex])
> -       | index |
> -       index := anInteger asInteger.
> -       (index < 1 or: [index + firstIndex - 1 > lastIndex])
>                ifTrue: [self errorNoSuchElement]
> +               ifFalse: [^array at: anInteger + firstIndex - 1 put: anObject]!
> -               ifFalse: [^array at: index + firstIndex - 1 put: anObject]!
>
> Item was changed:
> + ----- Method: OrderedCollection>>reset (in category 'removing') -----
> - ----- Method: OrderedCollection>>reset (in category 'private') -----
>  reset
> +       "Quickly remove all elements. The objects will be still referenced, but will not be     accessible."
> +
> -
>        self resetTo: 1!
>
> Item was changed:
> + ----- Method: OrderedCollection>>resetTo: (in category 'removing') -----
> - ----- Method: OrderedCollection>>resetTo: (in category 'private') -----
>  resetTo: index
> +       "Quickly remove all elements. The objects will be still referenced, but will not be     accessible. Also make sure that the first object will be inserted at index. Choosing the        right value has had great impact on performance, but it's neglible with the current     implementation, so it's better to use #reset instead in most cases."
> +
>        firstIndex := index.
>        lastIndex := firstIndex - 1!
>
>
>



More information about the Squeak-dev mailing list