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
public Object eval(String script) throws ScriptException {
131-
return eval(new StringReader(script));
131+
final Writer writer = getContext().getErrorWriter();
132+
try {
133+
final Class<?> clazz = compile(script);
134+
javaService.run(clazz);
135+
}
136+
catch (Exception e) {
137+
if (writer != null) {
138+
final PrintWriter err = new PrintWriter(writer);
139+
e.printStackTrace(err);
140+
err.flush();
141+
}
142+
else {
143+
if (e instanceof ScriptException) throw (ScriptException) e;
144+
throw new ScriptException(e);
145+
}
146+
}
147+
return null;
132148
}
133149

134150
/**
@@ -143,22 +159,14 @@ public Object eval(String script) throws ScriptException {
143159
*/
144160
@Override
145161
public Object eval(Reader reader) throws ScriptException {
146-
final Writer writer = getContext().getErrorWriter();
162+
String script;
147163
try {
148-
final Class<?> clazz = compile(reader);
149-
javaService.run(clazz);
150-
} catch (Exception e) {
151-
if (writer != null) {
152-
final PrintWriter err = new PrintWriter(writer);
153-
e.printStackTrace(err);
154-
err.flush();
155-
} else {
156-
if (e instanceof ScriptException)
157-
throw (ScriptException) e;
158-
throw new ScriptException(e);
159-
}
164+
script = getReaderContentsAsString(reader);
160165
}
161-
return null;
166+
catch (IOException e) {
167+
throw new ScriptException(e);
168+
}
169+
return eval(script);
162170
}
163171

164172
/**

0 commit comments

Comments
 (0)