From 6935fd4558230018aba678ead907b15a84108062 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Sat, 11 Oct 2003 19:34:29 +0000 Subject: [PATCH] Optimization: for line counting use offset of line icode of interpreter instead of the line itself. In this way interpreter does not need to read encoded line data on each line marker which can occur quite frequently. --- .../src/org/mozilla/javascript/Context.java | 9 ++++----- .../org/mozilla/javascript/Interpreter.java | 20 +++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/js/rhino/src/org/mozilla/javascript/Context.java b/js/rhino/src/org/mozilla/javascript/Context.java index aeaaf3140987..707295b3008c 100644 --- a/js/rhino/src/org/mozilla/javascript/Context.java +++ b/js/rhino/src/org/mozilla/javascript/Context.java @@ -2002,9 +2002,8 @@ public class Context { Context cx = getCurrentContext(); if (cx == null) return null; - if (cx.interpreterLine > 0 && cx.interpreterSourceFile != null) { - linep[0] = cx.interpreterLine; - return cx.interpreterSourceFile; + if (cx.interpreterData != null) { + return Interpreter.getSourcePositionFromStack(cx, linep); } /** * A bit of a hack, but the only way to get filename and line @@ -2208,8 +2207,8 @@ public class Context { private Hashtable activationNames; // For the interpreter to indicate line/source for error reports. - int interpreterLine; - String interpreterSourceFile; + int interpreterLineIndex; + InterpreterData interpreterData; // For instruction counting (interpreter only) int instructionCount; diff --git a/js/rhino/src/org/mozilla/javascript/Interpreter.java b/js/rhino/src/org/mozilla/javascript/Interpreter.java index 75416b0b9a4d..38b8e5c7ad1f 100644 --- a/js/rhino/src/org/mozilla/javascript/Interpreter.java +++ b/js/rhino/src/org/mozilla/javascript/Interpreter.java @@ -1571,7 +1571,8 @@ public class Interpreter } } - static int[] getLineNumbers(InterpreterData data) { + static int[] getLineNumbers(InterpreterData data) + { UintMap presentLines = new UintMap(); int iCodeLength = data.itsICodeTop; @@ -1589,6 +1590,13 @@ public class Interpreter return presentLines.getKeys(); } + + static String getSourcePositionFromStack(Context cx, int[] linep) + { + InterpreterData idata = cx.interpreterData; + linep[0] = getShort(idata.itsICode, cx.interpreterLineIndex); + return idata.itsSourceFile; + } static Object getEncodedSource(InterpreterData idata) { @@ -1739,8 +1747,8 @@ public class Interpreter debuggerFrame.onEnter(cx, scope, thisObj, args); } - String savedSourceFile = cx.interpreterSourceFile; - cx.interpreterSourceFile = idata.itsSourceFile; + InterpreterData savedData = cx.interpreterData; + cx.interpreterData = idata; Object result = undefined; // If javaException != null on exit, it will be throw instead of @@ -2665,9 +2673,9 @@ public class Interpreter break; } case Icode_LINE : { - int line = getShort(iCode, pc + 1); - cx.interpreterLine = line; + cx.interpreterLineIndex = pc + 1; if (debuggerFrame != null) { + int line = getShort(iCode, pc + 1); debuggerFrame.onLineChange(cx, line); } pc += 2; @@ -2701,7 +2709,7 @@ public class Interpreter } } - cx.interpreterSourceFile = savedSourceFile; + cx.interpreterData = savedData; if (debuggerFrame != null) { if (javaException != null) {