On 12 February 2011 18:41, Levente Uzonyi <leves@elte.hu> wrote:
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.
oh come on. Switch statement should live where it belongs to: C code. Why we should support this ridiculous syntax constructs in smalltalk? IMO: All users of such code should die. And i don't care if they are working fast or not.. This is plainly against the spirit of smalltalk.
Levente
-- Best regards, Igor Stasenko AKA sig.