Browse Source

Reuse old method contexts when possible

Nicolas Petton 13 years ago
parent
commit
1059861755
2 changed files with 26 additions and 14 deletions
  1. 1 1
      js/Compiler.deploy.js
  2. 25 13
      js/boot.js

File diff suppressed because it is too large
+ 1 - 1
js/Compiler.deploy.js


+ 25 - 13
js/boot.js

@@ -315,14 +315,19 @@ function Smalltalk(){
 	smalltalk.Error._signal_(receiver + ' is not a Jtalk object and "' + jsSelector + '" is undefined')
     };
 
+
+    /* Reuse old contexts stored in oldContexts */
+
+    st.oldContexts = [];
+
 	
     /* Handle thisContext pseudo variable */
     
     pushContext = function(receiver, selector, temps) {
 	if(thisContext) {
-	    return thisContext = thisContext.newContext({receiver: receiver, selector: selector, temps: temps});
+	    return thisContext = thisContext.newContext(receiver, selector, temps);
 	} else {
-	    return thisContext = new SmalltalkMethodContext({receiver: receiver, selector: selector, temps: temps});
+	    return thisContext = new SmalltalkMethodContext(receiver, selector, temps);
 	}
     };
 
@@ -395,21 +400,29 @@ function Smalltalk(){
     st.setDevelopmentMode();
 }
 
-function SmalltalkMethodContext(spec) {
+function SmalltalkMethodContext(receiver, selector, temps, home) {
     var that = this;
-    spec = spec || {};
-    that.homeContext = spec.homeContext;
-    that.selector = spec.selector;
-    that.receiver = spec.receiver;
-    that.temps = spec.temps || {};
-
-    that.newContext = function(spec) {
-	spec = spec || {};
-	return new SmalltalkMethodContext({homeContext: that, receiver: spec.receiver, selector: spec.selector, temps: spec.temps});
+    that.receiver = receiver;
+    that.selector = selector;
+    that.temps = temps || {};
+    that.homeContext = home;
+
+    that.newContext = function(receiver, selector, temps) {
+	var c = smalltalk.oldContexts.pop();
+	if(c) {
+	    c.homeContext = that;
+	    c.receiver = receiver;
+	    c.selector = selector;
+	    c.temps = temps || {};
+	} else {
+	    c = new SmalltalkMethodContext(receiver, selector, temps, that);
+	}
+	return c;
     }
 
     that.removeYourself = function() {
 	thisContext = that.homeContext;
+	smalltalk.oldContexts.push(that);
     }
 }
 
@@ -419,7 +432,6 @@ var nil = new SmalltalkNil();
 var smalltalk = new Smalltalk();
 var thisContext = undefined;
 
-
 /* Utilities */
 
 Array.prototype.remove = function(s){

Some files were not shown because too many files changed in this diff