Lookup.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 11 Oct 2011 16:53:59 +0100
branchjv
changeset 17883 209190914636
parent 17879 4ed4eb60a67e
child 17888 e650d3cb3084
permissions -rw-r--r--
svn:keywords property set correctly

"
 COPYRIGHT (c) 2006 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic' }"

Object subclass:#Lookup
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Classes'
!

!Lookup class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2006 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
! !

!Lookup class methodsFor:'initialization'!

initialize

    self lookupObject: Lookup builtin

    "Created: / 26-04-2010 / 21:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!Lookup class methodsFor:'accessing'!

builtin

    ^BuiltinLookup instance

    "Created: / 26-04-2010 / 19:26:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!Lookup methodsFor:'lookup'!

lookupMethodForSelector: selector directedTo: initialSearchClass

     |cls md method|

	"Following C code is just a performance optimization.
	 It is not neccessary, however it speeds up UI code,
	 since it heavily uses perform:"
%{
	RETURN (  __lookup(initialSearchClass, selector) );
%}.

     cls := initialSearchClass.
     [ cls notNil ] whileTrue:[
        md := cls methodDictionary.
        method := md at:selector ifAbsent:nil.
        method notNil ifTrue:[^ method ].
        cls := cls superclass.
     ].
     ^ nil

    "Created: / 27-04-2010 / 15:30:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext

    <resource: #obsolete>

	"
	 This method is no longer sent by the VM as it nows pass
	 inline/poly cache object. 
	"


    "invoked by the VM to ask me for a method to call.
     The arguments are: the selector, receiver and arguments,
     the class to start the search in (for here-, super and directed sends)
     the sending context.

     The returned method object will be put into the inline- and polyCache
     at the call site; it might therefore be called more than once for the
     same receiver-class/selector combination (once for each call site).
     If I return nil, a doesNotUnderstand will be invoked."

     |cls md method|

	"Following C code is just a performance optimization.
	 It is not neccessary, however it speeds up UI code,
	 since it heavily uses perform:"
%{
	RETURN (  __lookup(initialSearchClass, selector) );
%}.
    ^ self lookupMethodForSelector: selector 
		   directedTo: initialSearchClass


!

lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache

    "Invoked by the VM to ask me for a method to call.
     The arguments are: the selector, receiver and arguments,
     the class to start the search in (for here-, super and directed sends)
     the sending context and the inline/poly cache (instance of
	 PolymorphicInlineCache). 
	 	
     The returned method object will NOT be put into the inline- and 
	 polyCache bu default. To update the call site's cache, you have to
	 call ilcCache bindTo: method forClass: initialSearch class. If you
	 dont call it, inline/poly cache won't be updated and next call
	 won't be cached (therefore it will be relatively slow. 

     If I return nil, a doesNotUnderstand: will be send."


    | method |

	"Following C code is just a performance optimization.
	 It is not neccessary, however it speeds up UI code,
	 since it heavily uses perform:"

%{
    method = __lookup(initialSearchClass, selector);
    __ilcBind(ilcCache, initialSearchClass, method, selector);
    RETURN (method);
%}.

    method := self lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext.
    ilcCache bindTo: method forClass: initialSearchClass.
    ^ method.

    "Created: / 01-10-2011 / 13:18:40 / Jan Kurs <kursjan@fit.cvut.cz>"
! !

!Lookup class methodsFor:'documentation'!

version_SVN
    ^ '$Id: Lookup.st 10717 2011-10-11 15:53:59Z vranyj1 $'
! !

Lookup initialize!