cyclic looping with [0 == object] whileFalse: [object := object nextObject].

Paolo Bonzini bonzini at
Tue Nov 6 15:37:24 UTC 2007

> However given you are doing message sends, block evaluations etc in 
> allInstancesDo:. Then *MILLIONS* of bytecodes  and 100 of thousands of 
> method invocations run
> to do the same task.  Thus in a simple loop iterating over an object and 
> doing a message send to ask them if they are a Morph is *way faster*

Unfortunately, something like this would also be slower than #nextObject:

     Morph withAllSubclassesDo: [ :each |
         inst _ each someInstance.
         [inst == nil] whileFalse:
             [next _ inst nextInstance.
             inst removeProperty: #undoGrabCommand.
             inst _ next]

because of the *huge* amount of Morph subclasses in the image.    You 
are walking the object memory hundreds of times rather than one, and I 
found out a few years ago (on a different computer) that using a Set (!) 
and #nextObject is faster than using #nextInstance if you have about 20 
subclasses (or more).

This would work for Rob however.


More information about the Squeak-dev mailing list