Den 19.02.2010 14:03, skrev Levente Uzonyi:
> On Fri, 19 Feb 2010, Henrik Johansen wrote:
>
>   
>> Well, ugly was a strong word.
>> Reusing less, aka. shorter is a better choice, I guess.
>>     
> I think the difference is 3 lines for the 4 methods.
>
>   
>> Cheers,
>> Henry
>>
>> PS. In VisualWorks, the two perform equally. *Wishing for a Cog VM to
>> test on* :)
>>     
> There's no inlining VM available ATM (besides SqueakJ, but that can't 
> run current images) and noone knows when one will be. And even though I 
> didn't try it, I expect that "inlining by hand" saves time and memory.
>   
No objections here, it's definately faster.
>> PPS. For those interested, the alternative, faster version Levente made
>> can be found at http://paste.lisp.org/display/93130
>>     
> Here is a working example (the linked version has a bug):
> BlockClosure >> cull: argument1 cull: argument2
>
>       numArgs = 2 ifTrue: [ ^self value: argument1 value: argument2 ].
>       numArgs = 1 ifTrue: [ ^self value: argument1 ].
>       ^self value
>   
Ah yes, had forgotten about that.
How about:

 numArgs > 1 ifTrue: [ ^self value: argument1 value: argument2 ].
 numArgs = 1 ifTrue: [ ^self value: argument1 ].
 ^self value

That way, you get "This block accepts 3 arguments, but was called with 2 
arguments" instead of "... was called with 0 arguments" error messages if the 
block has too many args.

> (For #cull:cull:cull: the difference is ~1.7x if the block has 0 or 1 
> argument, and ~1.3x if it has 2 arguments)
>   
Then also consider the scale
"overhead of 120 ms rather than 320ms for 1 million cull:cull:cull:
sends where the block has one arg, compared to a raw value: send
(130ms)". ;)

Cheers,
Henry

_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to