[BUG]Collection>>removeAll:

goran.hultgren at bluefish.se goran.hultgren at bluefish.se
Wed Aug 21 14:58:17 UTC 2002


Ralph Johnson <johnson at cs.uiuc.edu> wrote:
> By the way, the way I'd write removeAll is
> 
> removeAll
>   [self isEmpty] whileFalse: [self removeAll: self]
> 
> Put it in Collection and perhaps that would solve your problem.

For most collections this is a special case that you can solve much more
efficiently.
In OrderedCollection I would like to have:

removeAll
	self setCollection: (Array new: array size)

That would drop the old array and create a new one of the same size.
Of course we could "nil out" all elements in the old array but I don't
know what's fastest.

But in Collection, sure, we can have "self removeAll: self" as a "worst
case" base implementation (assuming it works of course).

regards, Göran

PS. Code not tested so hey, don't blame me if it doesn't actually run...
:-) DS



More information about the Squeak-dev mailing list