[squeak-dev] did ifEmpty:ifNotEmpty: change?

Levente Uzonyi leves at elte.hu
Fri Mar 12 21:38:19 UTC 2010


On Fri, 12 Mar 2010, Chris Muller wrote:

> I know the semantics of ifEmpty: and ifNotEmpty: changed in the trunk
> image last year, to answer the receiver instead of nil in the other
> case.
>
> However, I also noticed ifEmpty:ifNotEmpty: changed but I'm not seeing
> any semantic difference.  Is there some subtlety I'm missing by the
> new:
>
> ifEmpty: emptyBlock ifNotEmpty: notEmptyBlock
> 	"Evaluate emptyBlock if I'm empty, notEmptyBlock otherwise"
> 	" If the notEmptyBlock has an argument, eval with the receiver as its argument"
>
> 	self isEmpty ifTrue: [ ^emptyBlock value ].
> 	^notEmptyBlock valueWithPossibleArgument: self

This version is faster than the old one, because ifTrue: is inlined.


Levente

>
> vs. old:
>
> ifEmpty: emptyBlock ifNotEmpty: notEmptyBlock
> 	"Evaluate emptyBlock if I'm empty, notEmptyBlock otherwise"
> 	" If the notEmptyBlock has an argument, eval with the receiver as its argument"
>
> 	^ self isEmpty ifTrue: emptyBlock ifFalse: [notEmptyBlock
> valueWithPossibleArgument: self]
>
> ?
>
> Thanks,
>  Chris
>
>



More information about the Squeak-dev mailing list