8198816: AbstractScriptEngine.getScriptContext creation of SimpleScriptContext is inefficient
Reviewed-by: sundar, jlaskey
This commit is contained in:
parent
60723b7e3d
commit
54d482220b
@ -287,7 +287,7 @@ public abstract class AbstractScriptEngine implements ScriptEngine {
|
||||
*/
|
||||
protected ScriptContext getScriptContext(Bindings nn) {
|
||||
|
||||
SimpleScriptContext ctxt = new SimpleScriptContext();
|
||||
SimpleScriptContext ctxt = new SimpleScriptContext(context.getReader(), context.getWriter(), context.getErrorWriter());
|
||||
Bindings gs = getBindings(ScriptContext.GLOBAL_SCOPE);
|
||||
|
||||
if (gs != null) {
|
||||
@ -301,10 +301,6 @@ public abstract class AbstractScriptEngine implements ScriptEngine {
|
||||
throw new NullPointerException("Engine scope Bindings may not be null.");
|
||||
}
|
||||
|
||||
ctxt.setReader(context.getReader());
|
||||
ctxt.setWriter(context.getWriter());
|
||||
ctxt.setErrorWriter(context.getErrorWriter());
|
||||
|
||||
return ctxt;
|
||||
|
||||
}
|
||||
|
@ -79,13 +79,10 @@ public abstract class CompiledScript {
|
||||
ScriptContext ctxt = getEngine().getContext();
|
||||
|
||||
if (bindings != null) {
|
||||
SimpleScriptContext tempctxt = new SimpleScriptContext();
|
||||
SimpleScriptContext tempctxt = new SimpleScriptContext(ctxt.getReader(), ctxt.getWriter(), ctxt.getErrorWriter());
|
||||
tempctxt.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
|
||||
tempctxt.setBindings(ctxt.getBindings(ScriptContext.GLOBAL_SCOPE),
|
||||
ScriptContext.GLOBAL_SCOPE);
|
||||
tempctxt.setWriter(ctxt.getWriter());
|
||||
tempctxt.setReader(ctxt.getReader());
|
||||
tempctxt.setErrorWriter(ctxt.getErrorWriter());
|
||||
ctxt = tempctxt;
|
||||
}
|
||||
|
||||
|
@ -86,11 +86,25 @@ public class SimpleScriptContext implements ScriptContext {
|
||||
* Create a {@code SimpleScriptContext}.
|
||||
*/
|
||||
public SimpleScriptContext() {
|
||||
this(new InputStreamReader(System.in),
|
||||
new PrintWriter(System.out , true),
|
||||
new PrintWriter(System.err, true));
|
||||
engineScope = new SimpleBindings();
|
||||
globalScope = null;
|
||||
reader = new InputStreamReader(System.in);
|
||||
writer = new PrintWriter(System.out , true);
|
||||
errorWriter = new PrintWriter(System.err, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Package-private constructor to avoid needless creation of reader and writers.
|
||||
* It is the caller's responsability to initialize the engine scope.
|
||||
*
|
||||
* @param reader the reader
|
||||
* @param writer the writer
|
||||
* @param errorWriter the error writer
|
||||
*/
|
||||
SimpleScriptContext(Reader reader, Writer writer, Writer errorWriter) {
|
||||
this.reader = reader;
|
||||
this.writer = writer;
|
||||
this.errorWriter = errorWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user