Behavior.st
branchjv
changeset 17783 3d93372f94fc
parent 17782 8bdc03fe9616
child 17790 59523f5d9254
--- a/Behavior.st	Mon Jul 19 10:29:28 2010 +0100
+++ b/Behavior.st	Tue Jul 20 11:55:14 2010 +0100
@@ -1153,26 +1153,33 @@
 ! !
 
 
-
 !Behavior methodsFor:'accessing'!
 
 addSelector:newSelector withMethod:newMethod
     "add the method given by 2nd argument under the selector given by
      1st argument to the methodDictionary. Flushes all caches."
 
-    |oldMethod|
+    |oldMethod ns selector |
 
     (newSelector isMemberOf:Symbol) ifFalse:[
-	self error:'invalid selector'.
+        self error:'invalid selector'.
     ].
-
-    oldMethod := self compiledMethodAt:newSelector.
+    
+    ns := newMethod nameSpace.
+    selector := ns
+                    ifNotNil:[(':' , ns name , '::' , newSelector) asSymbol]
+                    ifNil:[newSelector].
+
+
+    oldMethod := self compiledMethodAt:selector.
     oldMethod notNil ifTrue:[
-	newMethod restricted:(oldMethod isRestricted).
-	newMethod setPrivacy:(oldMethod privacy) flushCaches:false.
+        newMethod restricted:(oldMethod isRestricted).
+        newMethod setPrivacy:(oldMethod privacy) flushCaches:false.
     ].
 
-    (self primAddSelector:newSelector withMethod:newMethod) ifFalse:[^ false].
+    (self primAddSelector:selector withMethod:newMethod) ifFalse:[^ false].
+
+    ns ifNotNil:[self lookupObject: NamespaceAwareLookup].
 
     "
      if I have no subclasses, all we have to flush is cached
@@ -1181,12 +1188,12 @@
     "
 "
     problem: this is slower; since looking for all subclasses is (currently)
-	     a bit slow :-(
-	     We need the hasSubclasses-info bit in Behavior; now
+             a bit slow :-(
+             We need the hasSubclasses-info bit in Behavior; now
 
     self withAllSubclassesDo:[:aClass |
-	ObjectMemory flushInlineCachesFor:aClass withArgs:nargs.
-	ObjectMemory flushMethodCacheFor:aClass
+        ObjectMemory flushInlineCachesFor:aClass withArgs:nargs.
+        ObjectMemory flushMethodCacheFor:aClass
     ].
 "
 
@@ -1194,7 +1201,7 @@
     "/ pass the selector AND the old method as changeArg
     "/ - this allows for watchers to find out if its a new method or a method-change
     "/
-    self changed:#methodDictionary with:(Array with:newSelector with:oldMethod).
+    self changed:#methodDictionary with:(Array with:selector with:oldMethod).
 
     "/
     "/ also notify a change of Smalltalk;
@@ -1202,11 +1209,12 @@
     "/ changes (no need for observing all classes)
     "/ - this allows for watchers to find out if its a new method or a method-change
     "/
-    Smalltalk changed:#methodInClass with:(Array with:self with:newSelector with:oldMethod).
+    Smalltalk changed:#methodInClass with:(Array with:self with:selector with:oldMethod).
     ^ true.
 
     "Created: / 11-12-1995 / 13:59:37 / cg"
     "Modified: / 04-08-2006 / 11:39:28 / cg"
+    "Modified: / 20-07-2010 / 11:29:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 basicAddSelector:newSelector withMethod:newMethod
@@ -1363,7 +1371,6 @@
     ^ superclass
 ! !
 
-
 !Behavior methodsFor:'autoload check'!
 
 autoload
@@ -2814,47 +2821,29 @@
      I.e. executing obsolete methods, since the old method will still
      be executed out of the caches."
 
-    "JV@2010-07-19: Changed to support selector/language namespaces"
-
-    | oldDict oldSelector oldMethod newDict newSelector ns |
+    |dict oldMethod|
 
     newMethod isNil ifTrue:[
-        self error:'invalid method'.
+	self error:'invalid method'.
     ].
     (Smalltalk
-            changeRequest:#methodInClass
-            with:(Array with:self with:aSelector with:oldMethod)) ifFalse:[
-        ^ false
+	    changeRequest:#methodInClass
+	    with:(Array with:self with:aSelector with:oldMethod)) ifFalse:[
+	^ false
     ].
     "/ oldMethod := self compiledMethodAt:aSelector.
-    ns := newMethod nameSpace.
-    oldDict := self methodDictionary.
-    oldDict keysAndValuesDo:
-        [:sel :mthd|
-        (sel = aSelector "single = here!!!!!! we test for requality"
-            and:[mthd nameSpace = ns])
-                ifTrue:
-                    [oldSelector := sel.
-                    oldMethod := mthd]].
-
-    newSelector := oldMethod 
-        ifNotNil:
-            [oldSelector]
-        ifNil:
-            [ns ifNil:[aSelector] ifNotNil:[aSelector asString]].
-    newDict := oldDict at: newSelector putOrAppend: newMethod.
-
-    self setMethodDictionary:newDict.
-    
+
+    dict := self methodDictionary.
+    "/ oldMethod := dict at:aSelector ifAbsent:nil.
+
+    self setMethodDictionary:(dict at:aSelector putOrAppend:newMethod).
     newMethod mclass:self.
-    ns ifNotNil:[self lookupObject: NamespaceAwareLookup].
 
     ObjectMemory flushCachesForSelector:aSelector.
     ^ true
 
     "Modified: / 07-06-1996 / 14:48:45 / stefan"
     "Modified: / 31-08-2007 / 16:53:20 / cg"
-    "Modified: / 19-07-2010 / 11:20:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 setMethodDictionary:dict
@@ -4696,7 +4685,7 @@
 !Behavior class methodsFor:'documentation'!
 
 version
-    ^ '$Id: Behavior.st 10546 2010-07-19 09:29:28Z vranyj1 $'
+    ^ '$Id: Behavior.st 10548 2010-07-20 10:55:14Z vranyj1 $'
 !
 
 version_CVS
@@ -4704,5 +4693,5 @@
 !
 
 version_SVN
-    ^ '$Id: Behavior.st 10546 2010-07-19 09:29:28Z vranyj1 $'
+    ^ '$Id: Behavior.st 10548 2010-07-20 10:55:14Z vranyj1 $'
 ! !