Skip to content

Commit d607e9d

Browse files
committed
Avoid val() when returning from MSC.execute()
This can be noticed in profiling when passing arrays to iclosures, for example. In a lot of cases the string builder does not need to complete, so a potentially expensive CArray.val() can be avoided.
1 parent ca33762 commit d607e9d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/main/java/com/laytonsmith/core/MethodScriptCompiler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,10 +3087,13 @@ public static Mixed execute(ParseTree root, Environment env, MethodScriptComplet
30873087
Mixed retc = script.eval(gg, env);
30883088
if(root.numberOfChildren() == 1) {
30893089
returnable = retc;
3090+
if(done == null) {
3091+
// string builder is not needed, so return immediately
3092+
return returnable;
3093+
}
30903094
}
3091-
@SuppressWarnings("null")
3092-
String ret = retc instanceof CNull ? "null" : retc.val();
3093-
if(ret != null && !ret.trim().isEmpty()) {
3095+
String ret = retc.val();
3096+
if(!ret.trim().isEmpty()) {
30943097
b.append(ret).append(" ");
30953098
}
30963099
}

0 commit comments

Comments
 (0)