[Vm-dev] Primitive 60 vs methods with more than one argument

Levente Uzonyi leves at elte.hu
Sun Oct 20 02:40:32 UTC 2013


On Sat, 19 Oct 2013, David T. Lewis wrote:

>
> I think you are suggesting to use the argumentCount to determine the
> actual receiver and the first parameter, rather than assume that there
> is exactly one argument so that the top two stack values are used. Is
> that right?

Exactly.


Levente

>
> The only cost that I can see associated with this would be related to
> finding the receiver and the first parameter based on argumentCount.
> It might be a negligible difference, so it would be worth trying it to
> find out.
>
> Dave
>
>
> On Sat, Oct 19, 2013 at 10:53:40PM +0200, Levente Uzonyi wrote:
>>
>> Hi,
>>
>> the code of primitive 60 seems to be assuming that the method has exactly
>> one argument, ignoring the actual number of arguments. This seems to be an
>> unnecessary restriction, which makes it cumbersome/impossible to use it in
>> methods which have more arguments, like #at:ifAbsent:.
>>
>> Since the primitive uses two objects from the top of the stack, it's
>> possible to write a hackish method to see the potential benefits:
>>
>> ifAbsent: aBlock receiver: receiver at: index
>>
>> 	<primitive: 60>
>> 	^aBlock value
>>
>> The primitive will treat the variable receiver as the receiver, and index
>> as the index. The real receiver is not used at all.
>>
>> This method performs 37% better than #at:ifAbsent for the case where
>> the index is valid.
>>
>> Does it have any benefits not taking the actual number of arguments into
>> account in this primitive?
>>
>> Cheers,
>> Levente
>


More information about the Vm-dev mailing list