[Pharo-project] [update] #10453
stephane.ducasse at inria.fr
Tue Sep 15 15:54:06 EDT 2009
- adding removeAll to collections (missing some of them of course)
add #removeAll suport to collections
This is to solve both
Comments about the implementation:
The super implementation might be enhanced with a shallowCopy in order
to provide a working implementation in more cases:
self shallowCopy do: [:each | self remove: each].
I believe much subclasses will override, so I did not even bother.
Subclass implementation tries to preserve original capacity.
This choice is arbitrary and really depends on application side...
CharacterSetComplement use a #become:. This is not efficient, but
neither would be the addition of all existing characters to the
complement (this set is defined by its complement as the name tells).
Collection>>#removeAll: also has been modified to handle case of (self
removeAll: self). This extends and supersedes the changes from kwl at http://bugs.squeak.org/view.php?id=6937
The big question is what should (self removeAll: self) return?
My answer is simple: it returns self (an empty collection).
Beware, this will break some chaining:
(b removeAll: (a removeAll: a)) ~= (a removeAll: (b removeAll: a)).
Anyway, that is not worse than current implementation which will not
lead to the most predictible results.
More information about the Pharo-dev