Skip to content

Commit

Permalink
Avoid val() when returning from MSC.execute()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
PseudoKnight committed Feb 28, 2024
1 parent ca33762 commit d607e9d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/laytonsmith/core/MethodScriptCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3087,10 +3087,13 @@ public static Mixed execute(ParseTree root, Environment env, MethodScriptComplet
Mixed retc = script.eval(gg, env);
if(root.numberOfChildren() == 1) {
returnable = retc;
if(done == null) {
// string builder is not needed, so return immediately
return returnable;
}
}
@SuppressWarnings("null")
String ret = retc instanceof CNull ? "null" : retc.val();
if(ret != null && !ret.trim().isEmpty()) {
String ret = retc.val();
if(!ret.trim().isEmpty()) {
b.append(ret).append(" ");
}
}
Expand Down

0 comments on commit d607e9d

Please sign in to comment.