--- a/Method.st Thu Mar 09 10:45:46 1995 +0100
+++ b/Method.st Thu Mar 09 11:44:00 1995 +0100
@@ -12,7 +12,9 @@
CompiledCode subclass:#Method
instanceVariableNames:'source sourcePosition category package'
- classVariableNames:'PrivateMethodSignal LastFileReference LastSourceFileName'
+ classVariableNames:'PrivateMethodSignal
+ LastFileReference LastSourceFileName
+ LastWhoClass'
poolDictionaries:''
category:'Kernel-Methods'
!
@@ -21,7 +23,7 @@
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libbasic/Method.st,v 1.29 1995-03-08 23:38:42 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Method.st,v 1.30 1995-03-09 10:44:00 claus Exp $
'!
!Method class methodsFor:'documentation'!
@@ -42,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libbasic/Method.st,v 1.29 1995-03-08 23:38:42 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Method.st,v 1.30 1995-03-09 10:44:00 claus Exp $
"
!
@@ -571,17 +573,46 @@
- the information about which class the original method was
defined in is lost in this case.
- Q: should we add a backref from the method to the class ?"
+ Problem: this is heavily called for in the debugger to create
+ a readable context walkback. For unbound methods, it is
+ slow, since the search (over all classes) will always fail.
+ Q: should we add a backref from the method to the class
+ and/or add a subclass of Method for unbound ones ?"
+
+ |classes cls sel|
+
+ "
+ very first, look in the class we found something the last time
+ this may often give a hit, when asking who repeatingly for
+ a context chain. (keep last by its name, to not keep classes from
+ being garbage collected)
+ "
+ LastWhoClass notNil ifTrue:[
+ cls := Smalltalk at:LastWhoClass.
+ sel := cls selectorForMethod:self.
+ sel notNil ifTrue:[^ Array with:cls with:sel].
+ ].
"
first, limit the search to global classes only -
since probability is high, that the receiver is found in there ...
"
- Smalltalk allBehaviorsDo:[:aClass |
+ classes := Smalltalk allBehaviors.
+ "
+ instance methods are usually more common - search those first
+ "
+ classes do:[:aClass |
|sel|
sel := aClass selectorForMethod:self.
- sel notNil ifTrue:[^ Array with:aClass with:sel].
+ sel notNil ifTrue:[LastWhoClass := aClass name.
+ ^ Array with:aClass with:sel].
+ ].
+
+ LastWhoClass := nil.
+ classes do:[:aClass |
+ |sel|
+
sel := aClass class selectorForMethod:self.
sel notNil ifTrue:[^ Array with:aClass class with:sel].
].