On 30 Mrz., 01:24, wolffiex <[email protected]> wrote: > Hi everyone, > From the docs, I couldn't quite tell: is compiling a Script using > compileReader the same as calling setOptimizationLevel? ie is this: > > Script script = context.compileReader(fileReader, packageName, > 1, null); > return script.exec(context, newScope); > > pretty much the same as this? > context.setOptimizationLevel(1); > context.evaluateReader(fileReader, packageName, 1, null); > > or is the optimization level about the way the context runs the > script?
Context.evaluateReader() is nothing more than a method that wraps Context.compileReader() followed by Script.exec() as you can see here: http://mxr.mozilla.org/mozilla/source/js/rhino/src/org/mozilla/javascript/Context.java#1112 the effect of the optimization level is the same for both: compileReader() will return an script that relies on Rhino's interpreter for a value of -1, while values >= 0 will return a script that is a java class that was generated on the fly. The rule is: if you need to run a script just once use evaluateReader (). If you plan to run it multiple times compile it once and cache the resulting script, and just run Script.exec() each time you need it. Hannes > Thanks, > A _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
