[squeak-dev] did ifEmpty:ifNotEmpty: change?
Nicolas Cellier
nicolas.cellier.aka.nice at gmail.com
Fri Mar 12 21:09:07 UTC 2010
2010/3/12 Chris Muller <ma.chris.m at gmail.com>:
> 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
>
> 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
>
Well, just take a look to bytecodes generated by each variant.
Only an optimization I think.
Nicolas
More information about the Squeak-dev
mailing list
|