mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
Small optimization for passing string literals to JS
This commit is contained in:
parent
25310a5082
commit
c743c8d3c1
|
@ -18,6 +18,7 @@ package org.teavm.jso.plugin;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.teavm.codegen.SourceWriter;
|
import org.teavm.codegen.SourceWriter;
|
||||||
import org.teavm.dependency.*;
|
import org.teavm.dependency.*;
|
||||||
|
import org.teavm.javascript.Renderer;
|
||||||
import org.teavm.javascript.ast.ConstantExpr;
|
import org.teavm.javascript.ast.ConstantExpr;
|
||||||
import org.teavm.javascript.ast.Expr;
|
import org.teavm.javascript.ast.Expr;
|
||||||
import org.teavm.javascript.ast.InvocationExpr;
|
import org.teavm.javascript.ast.InvocationExpr;
|
||||||
|
@ -127,6 +128,13 @@ public class JSNativeGenerator implements Injector, DependencyPlugin, Generator
|
||||||
break;
|
break;
|
||||||
case "wrap":
|
case "wrap":
|
||||||
if (methodRef.getDescriptor().parameterType(0).isObject("java.lang.String")) {
|
if (methodRef.getDescriptor().parameterType(0).isObject("java.lang.String")) {
|
||||||
|
if (context.getArgument(0) instanceof ConstantExpr) {
|
||||||
|
ConstantExpr constant = (ConstantExpr)context.getArgument(0);
|
||||||
|
if (constant.getValue() instanceof String) {
|
||||||
|
writer.append('"').append(Renderer.escapeString((String)constant.getValue())).append('"');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
writer.append("$rt_ustr(");
|
writer.append("$rt_ustr(");
|
||||||
context.writeExpr(context.getArgument(0));
|
context.writeExpr(context.getArgument(0));
|
||||||
writer.append(")");
|
writer.append(")");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user