Use the build-in valueOf method instead of the custom one.

This commit is contained in:
Jack Conradson 2016-05-20 11:13:43 -07:00
parent d836194095
commit 0e24ed49e6
2 changed files with 3 additions and 49 deletions

View File

@ -33,12 +33,6 @@ import java.util.ArrayList;
import java.util.Deque; import java.util.Deque;
import java.util.List; import java.util.List;
import static org.elasticsearch.painless.WriterConstants.BOOLEAN_OBJECT;
import static org.elasticsearch.painless.WriterConstants.BOOLEAN_VALUE_OF;
import static org.elasticsearch.painless.WriterConstants.BYTE_OBJECT;
import static org.elasticsearch.painless.WriterConstants.BYTE_VALUE_OF;
import static org.elasticsearch.painless.WriterConstants.CHARACTER_OBJECT;
import static org.elasticsearch.painless.WriterConstants.CHARACTER_VALUE_OF;
import static org.elasticsearch.painless.WriterConstants.CHAR_TO_STRING; import static org.elasticsearch.painless.WriterConstants.CHAR_TO_STRING;
import static org.elasticsearch.painless.WriterConstants.DEF_ADD_CALL; import static org.elasticsearch.painless.WriterConstants.DEF_ADD_CALL;
import static org.elasticsearch.painless.WriterConstants.DEF_AND_CALL; import static org.elasticsearch.painless.WriterConstants.DEF_AND_CALL;
@ -64,22 +58,12 @@ import static org.elasticsearch.painless.WriterConstants.DEF_TO_LONG_EXPLICIT;
import static org.elasticsearch.painless.WriterConstants.DEF_TO_LONG_IMPLICIT; import static org.elasticsearch.painless.WriterConstants.DEF_TO_LONG_IMPLICIT;
import static org.elasticsearch.painless.WriterConstants.DEF_TO_SHORT_EXPLICIT; import static org.elasticsearch.painless.WriterConstants.DEF_TO_SHORT_EXPLICIT;
import static org.elasticsearch.painless.WriterConstants.DEF_TO_SHORT_IMPLICIT; import static org.elasticsearch.painless.WriterConstants.DEF_TO_SHORT_IMPLICIT;
import static org.elasticsearch.painless.WriterConstants.DEF_UTIL_TYPE;
import static org.elasticsearch.painless.WriterConstants.DEF_USH_CALL; import static org.elasticsearch.painless.WriterConstants.DEF_USH_CALL;
import static org.elasticsearch.painless.WriterConstants.DEF_UTIL_TYPE;
import static org.elasticsearch.painless.WriterConstants.DEF_XOR_CALL; import static org.elasticsearch.painless.WriterConstants.DEF_XOR_CALL;
import static org.elasticsearch.painless.WriterConstants.DOUBLE_OBJECT;
import static org.elasticsearch.painless.WriterConstants.DOUBLE_VALUE_OF;
import static org.elasticsearch.painless.WriterConstants.FLOAT_OBJECT;
import static org.elasticsearch.painless.WriterConstants.FLOAT_VALUE_OF;
import static org.elasticsearch.painless.WriterConstants.INDY_STRING_CONCAT_BOOTSTRAP_HANDLE; import static org.elasticsearch.painless.WriterConstants.INDY_STRING_CONCAT_BOOTSTRAP_HANDLE;
import static org.elasticsearch.painless.WriterConstants.INTEGER_OBJECT;
import static org.elasticsearch.painless.WriterConstants.INTEGER_VALUE_OF;
import static org.elasticsearch.painless.WriterConstants.LONG_OBJECT;
import static org.elasticsearch.painless.WriterConstants.LONG_VALUE_OF;
import static org.elasticsearch.painless.WriterConstants.MAX_INDY_STRING_CONCAT_ARGS; import static org.elasticsearch.painless.WriterConstants.MAX_INDY_STRING_CONCAT_ARGS;
import static org.elasticsearch.painless.WriterConstants.PAINLESS_ERROR_TYPE; import static org.elasticsearch.painless.WriterConstants.PAINLESS_ERROR_TYPE;
import static org.elasticsearch.painless.WriterConstants.SHORT_OBJECT;
import static org.elasticsearch.painless.WriterConstants.SHORT_VALUE_OF;
import static org.elasticsearch.painless.WriterConstants.STRINGBUILDER_APPEND_BOOLEAN; import static org.elasticsearch.painless.WriterConstants.STRINGBUILDER_APPEND_BOOLEAN;
import static org.elasticsearch.painless.WriterConstants.STRINGBUILDER_APPEND_CHAR; import static org.elasticsearch.painless.WriterConstants.STRINGBUILDER_APPEND_CHAR;
import static org.elasticsearch.painless.WriterConstants.STRINGBUILDER_APPEND_DOUBLE; import static org.elasticsearch.painless.WriterConstants.STRINGBUILDER_APPEND_DOUBLE;
@ -175,11 +159,11 @@ public final class MethodWriter extends GeneratorAdapter {
writeCast(from, to); writeCast(from, to);
unbox(to.type); unbox(to.type);
} else if (cast.boxFrom) { } else if (cast.boxFrom) {
box(from.type); valueOf(from.type);
writeCast(from, to); writeCast(from, to);
} else if (cast.boxTo) { } else if (cast.boxTo) {
writeCast(from, to); writeCast(from, to);
box(to.type); valueOf(to.type);
} else { } else {
writeCast(from, to); writeCast(from, to);
} }
@ -200,26 +184,6 @@ public final class MethodWriter extends GeneratorAdapter {
} }
} }
/**
* ASM does boxing in an evil way to be compatible with Java prior to verison 5.
* Supporting versions prior to 5 is not a requirement of this project, so the modern
* boxing methods are used instead.
*/
@Override
public void box(final org.objectweb.asm.Type type) {
switch (type.getSort()) {
case org.objectweb.asm.Type.VOID: visitInsn(Opcodes.ACONST_NULL); break;
case org.objectweb.asm.Type.BOOLEAN: invokeStatic(BOOLEAN_OBJECT , BOOLEAN_VALUE_OF); break;
case org.objectweb.asm.Type.BYTE: invokeStatic(BYTE_OBJECT , BYTE_VALUE_OF); break;
case org.objectweb.asm.Type.SHORT: invokeStatic(SHORT_OBJECT , SHORT_VALUE_OF); break;
case org.objectweb.asm.Type.CHAR: invokeStatic(CHARACTER_OBJECT, CHARACTER_VALUE_OF); break;
case org.objectweb.asm.Type.INT: invokeStatic(INTEGER_OBJECT , INTEGER_VALUE_OF); break;
case org.objectweb.asm.Type.LONG: invokeStatic(LONG_OBJECT , LONG_VALUE_OF); break;
case org.objectweb.asm.Type.FLOAT: invokeStatic(FLOAT_OBJECT , FLOAT_VALUE_OF); break;
case org.objectweb.asm.Type.DOUBLE: invokeStatic(DOUBLE_OBJECT , DOUBLE_VALUE_OF); break;
}
}
public void writeBranch(final Label tru, final Label fals) { public void writeBranch(final Label tru, final Label fals) {
if (tru != null) { if (tru != null) {
visitJumpInsn(Opcodes.IFNE, tru); visitJumpInsn(Opcodes.IFNE, tru);

View File

@ -147,16 +147,6 @@ public final class WriterConstants {
public final static Type FLOAT_OBJECT = Type.getType(Float.class); public final static Type FLOAT_OBJECT = Type.getType(Float.class);
public final static Type DOUBLE_OBJECT = Type.getType(Double.class); public final static Type DOUBLE_OBJECT = Type.getType(Double.class);
/** box methods to replace the GeneratorAdapter's slow way of boxing */
public final static Method BOOLEAN_VALUE_OF = getAsmMethod(Boolean.class , "valueOf", boolean.class);
public final static Method BYTE_VALUE_OF = getAsmMethod(Byte.class , "valueOf", byte.class);
public final static Method SHORT_VALUE_OF = getAsmMethod(Short.class , "valueOf", short.class);
public final static Method CHARACTER_VALUE_OF = getAsmMethod(Character.class, "valueOf", char.class);
public final static Method INTEGER_VALUE_OF = getAsmMethod(Integer.class , "valueOf", int.class);
public final static Method LONG_VALUE_OF = getAsmMethod(Long.class , "valueOf", long.class);
public final static Method FLOAT_VALUE_OF = getAsmMethod(Float.class , "valueOf", float.class);
public final static Method DOUBLE_VALUE_OF = getAsmMethod(Double.class , "valueOf", double.class);
private static Method getAsmMethod(final Class<?> rtype, final String name, final Class<?>... ptypes) { private static Method getAsmMethod(final Class<?> rtype, final String name, final Class<?>... ptypes) {
return new Method(name, MethodType.methodType(rtype, ptypes).toMethodDescriptorString()); return new Method(name, MethodType.methodType(rtype, ptypes).toMethodDescriptorString());
} }