[Pharo-project] could we agree to remove caseOf: and caseOf:otherwise:

Levente Uzonyi leves at elte.hu
Sat Feb 12 18:41:09 CET 2011


On Fri, 11 Feb 2011, stephane ducasse wrote:

> Hi guys
>
> let us do another pass at cleaning and realigning the system.
> Could we agree to deprecate caseOf: and caseOf:otherwise:?
> it will simply the compiler, decompiler and also we do not need that at all.
>
> | z | z := {[#a]->[1+1]. ['b' asSymbol]->[2+2]. [#c]->[3+3]}. #b caseOf: z
>
> =>
> "| z | z := {[#a]->[1+1]. ['b' asSymbol]->[2+2]. [#c]->[3+3]}.
> z detect: [:each | each key value = #b] "
>
> there is one user which I fixing right now.

IMHO you shouldn't remove it. There are a lot more users of this method 
(16 in the Pharo image I have and a lot more in external packages), but 
this method is inlined by the compiler, so you won't see it in the senders 
list. Try this instead:

SystemNavigation default browseMethodsWithSourceString: 'caseOf:'.

Using #detect: and #detect:ifNone: with a dynamically created array is a 
_lot_ slower than the inlined #caseOf: and #caseOf:otherwise:. For 
example:

[ 1 to: 10 do: [ :each |
 	each
 		caseOf: {
 			[ 1 ] -> [ $a ].
 			[ 2 ] -> [ $b ].
 			[ 3 ] -> [ $c ].
 			[ 4 ] -> [ $d ].
 			[ 5 ] -> [ $e ] }
 		otherwise: [ $x ] ] ] bench.
'1,790,000 per second.'.

[ 1 to: 10 do: [ :each |
 	({
 		[ 1 ] -> [ $a ].
 		[ 2 ] -> [ $b ].
 		[ 3 ] -> [ $c ].
 		[ 4 ] -> [ $d ].
 		[ 5 ] -> [ $e ] }
 			detect: [ :ea | ea key value = each ]
 			ifNone: [ [ $x ] ]) value ] ] bench.
'66,600 per second.'

~27x slowdown in this case.


Levente




More information about the Pharo-project mailing list