[squeak-dev] The defaullt implementation of isEmpty might do too much work

Eliot Miranda eliot.miranda at gmail.com
Thu Oct 20 17:26:51 UTC 2016


Nicolas,

On Thu, Oct 20, 2016 at 9:40 AM, Nicolas Cellier <
nicolas.cellier.aka.nice at gmail.com> wrote:

> The default behavior is to rely on ^self size = 0.
> But default size is doing too much (it iterates over all elements).
> It's OK for most of our classes which know very well about their size and
> override #size.
> It's not OK for an eventually lazy or infinite subclass.
>

Good catch.  Change it!

isEmpty
    self do: [:element| ^false].
    ^true



> I realized this by answering http://stackoverflow.com/
> questions/40149826/is-there-a-construct-like-iterate-
> iterable-if-it-has-elements-else
>

_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20161020/81196060/attachment.htm


More information about the Squeak-dev mailing list