Skip to content

Commit fededa4

Browse files
committed
Swap execution order of eval(String) and eval(Reader)
This order is much more efficient with the recently swapped execution order of compile(String) and compile(Reader). See e663151. Signed-off-by: Squareys <[email protected]>
1 parent 4913afd commit fededa4

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

‎src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,23 @@ public class JavaEngine extends AbstractScriptEngine{
128128
*/
129129
@Override
130130
publicObjecteval(Stringscript) throwsScriptException{
131-
returneval(newStringReader(script));
131+
finalWriterwriter = getContext().getErrorWriter();
132+
try{
133+
finalClass<?> clazz = compile(script);
134+
javaService.run(clazz);
135+
}
136+
catch (Exceptione){
137+
if (writer != null){
138+
finalPrintWritererr = newPrintWriter(writer);
139+
e.printStackTrace(err);
140+
err.flush();
141+
}
142+
else{
143+
if (einstanceofScriptException) throw (ScriptException) e;
144+
thrownewScriptException(e);
145+
}
146+
}
147+
returnnull;
132148
}
133149

134150
/**
@@ -143,22 +159,14 @@ public Object eval(String script) throws ScriptException{
143159
*/
144160
@Override
145161
publicObjecteval(Readerreader) throwsScriptException{
146-
finalWriterwriter = getContext().getErrorWriter();
162+
Stringscript;
147163
try{
148-
finalClass<?> clazz = compile(reader);
149-
javaService.run(clazz);
150-
} catch (Exceptione){
151-
if (writer != null){
152-
finalPrintWritererr = newPrintWriter(writer);
153-
e.printStackTrace(err);
154-
err.flush();
155-
} else{
156-
if (einstanceofScriptException)
157-
throw (ScriptException) e;
158-
thrownewScriptException(e);
159-
}
164+
script = getReaderContentsAsString(reader);
160165
}
161-
returnnull;
166+
catch (IOExceptione){
167+
thrownewScriptException(e);
168+
}
169+
returneval(script);
162170
}
163171

164172
/**

0 commit comments

Comments
(0)