[Newbies] Re: Recap: How to empty a collection
janko.mivsek at eranova.si
Wed Feb 20 09:53:53 UTC 2008
This is the last change, I promise :) Previous solution was for
collections in general, while for OrderedCollection you can simply do:
self setCollection: Array new.
A bit optimized method will therefore be:
"remove all elements quickly"
self setCollection: (Array new: 10). "Squeak specific"
self become: OrderedCollection new " "VW specific"
Janko Mivšek wrote:
> Ok, I reimplemented this method as Bert suggested and in the next
> version of Aida/Web it will be:
> "remove all elements quickly"
> self removeAllSuchThat: [:each | true]. "Squeak specific"
> " self become: OrderedCollection new " "VW specific"
> Note that this method is still an extension of Aida and it must
> therefore be portable among dialects, which is the reason of commented
> code for VW above.
> Best regards
> Bert Freudenberg wrote:
>> On Feb 20, 2008, at 2:01 , nicolas cellier wrote:
>>>> One thing I wasn't clear on is whether Bert's suggestion:
>>>> aColl removeAllSuchThat: [:anElement| true].
>>>> Is okay, and why it's okay while many of the other similar
>>>> approaches were not.
>>> Bert's suggestion is simple and works well.
>>> The only question is about efficiency.
>>> Up to (Down to?) subclasses to optimize it.
>> #removeAllSuchThat: is actually optimized in subclasses (look at its
>> implementation in OrderedCollection).
Smalltalk Web Application Server
More information about the Beginners