Browse Source

boot.js: some speedup

st.withContext does not contain try/catch part, extracted.
It allows Chrome to optimize it.
Adds cca 10% according to tinyBenchmarks.
Herbert Vojčík 9 years ago
parent
commit
c5c5e85064
1 changed files with 17 additions and 22 deletions
  1. 17 22
      support/boot.js

+ 17 - 22
support/boot.js

@@ -855,22 +855,27 @@ define("amber/boot", [ 'require', './browser-compatibility' ], function (require
 			if(thisContext) {
 				return inContext(worker, setup);
 			} else {
-				try {
-					return inContext(worker, setup);
-				} catch(error) {
-					handleError(error);
-					thisContext = null;
-					// Rethrow the error in any case.
-					error.amberHandled = true;
-					throw error;
-				}
+				return inContextWithErrorHandling(worker, setup);
 			}
 		};
 
+		function inContextWithErrorHandling(worker, setup) {
+			try {
+				return inContext(worker, setup);
+			} catch (error) {
+				handleError(error);
+				thisContext = null;
+				// Rethrow the error in any case.
+				error.amberHandled = true;
+				throw error;
+			}
+		}
+
 		function inContext(worker, setup) {
-			var context = pushContext(setup);
-			var result = worker(context);
-			popContext(context);
+			var oldContext = thisContext;
+			thisContext = new SmalltalkMethodContext(thisContext, setup);
+			var result = worker(thisContext);
+			thisContext = oldContext;
 			return result;
 		}
 
@@ -930,16 +935,6 @@ define("amber/boot", [ 'require', './browser-compatibility' ], function (require
 				return nil;
 			}
 		};
-
-		function pushContext(setup) {
-			thisContext = new SmalltalkMethodContext(thisContext, setup);
-			return thisContext;
-		}
-
-		function popContext(context) {
-			thisContext = context.homeContext;
-		}
-
 	}
 
 	function MessageSendBrik(brikz, st) {