On Mar 30, 3:18 am, Hannes Wallnoefer <[email protected]> wrote: > 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/javasc... > > 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
Thanks Hannes! I updated the wiki with the following: https://developer.mozilla.org/En/Rhino_Optimization > Scripts are optimized at compile time, not at execution time. So if a Script > is compiled with the context's optimizationLevel set to 1, it will be > executed with those optimizations, regardless of the optimizationLevel of the > context in which it is executed. Please let me know if this incorrect. Thanks again, A _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
