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

Levente Uzonyi leves at elte.hu
Sat Oct 19 20:53:40 UTC 2013


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?


More information about the Vm-dev mailing list