Skip to content

Commit

Permalink
It is more efficient to allow the VM to manage the auto-boxing of cer…
Browse files Browse the repository at this point in the history
…tain primitives than it is to invoke the (apache#3821)

It is more efficient to allow the VM to manage the auto-boxing of certain primitives than it is to invoke the object constructor.

This change cleans up Byte & Short for this.

Tests have been left untouched because we expressly want to handle the autoboxing in each particular test.
  • Loading branch information
BradWalker authored Mar 21, 2022
1 parent b565cfa commit ce03e1d
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1468,11 +1468,11 @@ public Object read(String className, Properties properties) {
if (classNames[0].equals(className)) {
return Boolean.valueOf(properties.getBoolean(propertyName, false));
} else if (classNames[1].equals(className)) {
return new Byte(properties.getByte(propertyName, (byte) 0));
return properties.getByte(propertyName, (byte)0);
} else if (classNames[2].equals(className)) {
return new Character(properties.getChar(propertyName, (char) 0));
} else if (classNames[3].equals(className)) {
return new Short(properties.getShort(propertyName, (short) 0));
return properties.getShort(propertyName, (short)0);
} else if (classNames[4].equals(className)) {
return Integer.valueOf(properties.getInt(propertyName, 0));
} else if (classNames[5].equals(className)) {
Expand Down
6 changes: 3 additions & 3 deletions ide/html.lexer/src/org/netbeans/lib/html/lexer/HtmlLexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public Token<HTMLTokenId> nextToken() {
if(input.readLength() > closeDelimiter.length()) {
input.backup(closeDelimiter.length());
//save the provider's index in the token's property so we can set the corresponding embdding in HTMLTokenId.language()
return token(HTMLTokenId.EL_CONTENT, new HtmlTokenPropertyProvider(EL_CONTENT_PROVIDER_INDEX, new Byte((byte)(customELIndex - 1))));
return token(HTMLTokenId.EL_CONTENT, new HtmlTokenPropertyProvider(EL_CONTENT_PROVIDER_INDEX, (byte)(customELIndex - 1)));
} else {
//return the open symbol token and switch to "in el" state
lexerState = INIT;
Expand Down Expand Up @@ -1088,7 +1088,7 @@ public Token<HTMLTokenId> nextToken() {
if(input.readLength() > closeDelimiter.length()) {
input.backup(closeDelimiter.length());
//save the provider's index in the token's property so we can set the corresponding embdding in HTMLTokenId.language()
return token(HTMLTokenId.EL_CONTENT, new HtmlTokenPropertyProvider(EL_CONTENT_PROVIDER_INDEX, new Byte((byte)(customELIndex - 1))));
return token(HTMLTokenId.EL_CONTENT, new HtmlTokenPropertyProvider(EL_CONTENT_PROVIDER_INDEX, (byte)(customELIndex - 1)));
} else {
//return the close symbol token and switch to "in value" state
lexerState = ISI_VAL_QUOT;
Expand Down Expand Up @@ -1416,7 +1416,7 @@ public Token<HTMLTokenId> nextToken() {

case ISI_EL:
case ISI_VAL_QUOT_EL:
return token(HTMLTokenId.EL_CONTENT, new HtmlTokenPropertyProvider(EL_CONTENT_PROVIDER_INDEX, new Byte((byte)(customELIndex - 1))));
return token(HTMLTokenId.EL_CONTENT, new HtmlTokenPropertyProvider(EL_CONTENT_PROVIDER_INDEX, (byte)(customELIndex - 1)));


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static String percentDecode(String text) {
List<Byte> bytes = new ArrayList<>();
while (text.length() > (i + 2) && text.charAt(i) == '%') {
int v = Integer.parseInt(text.substring(i+1, i+3), 16);
bytes.add(new Byte((byte) (v & 0xFF)));
bytes.add((byte)(v & 0xFF));
i += 3;
}
byte[] byteArray = new byte[bytes.size()];
Expand Down
50 changes: 25 additions & 25 deletions ide/schema2beans/src/org/netbeans/modules/schema2beans/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,33 +367,33 @@ public static Object getComparableObject(Object obj) {
}

public static Object defaultScalarValue(int type) {
switch(type & Common.MASK_TYPE) {
case Common.TYPE_STRING:
return ""; // NOI18N
case Common.TYPE_COMMENT:
return ""; // NOI18N
case Common.TYPE_BOOLEAN:
return Boolean.FALSE;
case Common.TYPE_BYTE:
return new Byte((byte)0);
case Common.TYPE_CHAR:
return new Character('\0');
case Common.TYPE_SHORT:
return new Short((short)0);
case Common.TYPE_INT:
return Integer.valueOf(0);
case Common.TYPE_LONG:
return new Long(0);
case Common.TYPE_FLOAT:
return new Float(0.0);
case Common.TYPE_DOUBLE:
return new Double(0.0);
default:
throw new IllegalArgumentException(Common.getMessage(
"UnknownType_msg", Integer.valueOf(type)));
switch (type & Common.MASK_TYPE) {
case Common.TYPE_STRING:
return ""; // NOI18N
case Common.TYPE_COMMENT:
return ""; // NOI18N
case Common.TYPE_BOOLEAN:
return Boolean.FALSE;
case Common.TYPE_BYTE:
return (byte)0;
case Common.TYPE_CHAR:
return new Character('\0');
case Common.TYPE_SHORT:
return (short)0;
case Common.TYPE_INT:
return Integer.valueOf(0);
case Common.TYPE_LONG:
return new Long(0);
case Common.TYPE_FLOAT:
return new Float(0.0);
case Common.TYPE_DOUBLE:
return new Double(0.0);
default:
throw new IllegalArgumentException(Common.getMessage(
"UnknownType_msg", Integer.valueOf(type)));
}
}


/*
* Bundle utility methods. The following methods return a formated message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,11 @@ public Object defaultScalarValue(int type) {
case Common.TYPE_BOOLEAN:
return Boolean.FALSE;
case Common.TYPE_BYTE:
return new Byte((byte)0);
return (byte)0;
case Common.TYPE_CHAR:
return new Character('\0');
case Common.TYPE_SHORT:
return new Short((short)0);
return (short)0;
case Common.TYPE_INT:
return Integer.valueOf(0);
case Common.TYPE_LONG:
Expand All @@ -902,7 +902,7 @@ public Object defaultScalarValue(int type) {
case Common.TYPE_DOUBLE:
return new Double(0.0);
default:
throw new IllegalArgumentException(Common.getMessage("UnknownType", type));
throw new IllegalArgumentException(Common.getMessage("UnknownType", type));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
* both after the invocation of the expression and invocation of the method.
*
* @author Martin Entlicher
*
* WARNING: Do not change any of the primitive auto-boxing. It could potentially
* break the tests. We expressly want it done as part of testing.
*/
public class EvaluatorApp extends BaseClass {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private static void addAllAsReferenceType(List list, int[] values) {

private static void addAllAsReferenceType(List list, short[] values) {
for (int i = 0; i < values.length; i++) {
list.add(new Short(values[i]));
list.add(values[i]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl

if (retClass.isPrimitive()) {
if (retClass == Byte.TYPE) {
return new Byte((byte)0);
return (byte)0;
} else if (retClass == Short.TYPE) {
return new Short((short)0);
return (short)0;
} else if (retClass == Integer.TYPE) {
return new Integer(0);
} else if (retClass == Long.TYPE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ private ArrayWrapper readNewArray() throws IOException {
aw.values = new ArrayList<Object>(size);
for (int i = 0; i < size; i++) {
if (aw.classdesc.name.equals("[B")) { // NOI18N
aw.values.add(new Byte(readByte()));
aw.values.add(readByte());
} else if (aw.classdesc.name.equals("[S")) { // NOI18N
aw.values.add(new Short(readShort()));
aw.values.add(readShort());
} else if (aw.classdesc.name.equals("[I")) { // NOI18N
aw.values.add(new Integer(readInt()));
} else if (aw.classdesc.name.equals("[J")) { // NOI18N
Expand Down Expand Up @@ -553,13 +553,13 @@ private byte[] readBlockDataLong() throws IOException {

private List<NameValue> readNoWrClass(ClassDesc cd) throws IOException {
List<FieldDesc> fields = cd.fields;
List<NameValue> values = new ArrayList<NameValue>(fields.size());
List<NameValue> values = new ArrayList<>(fields.size());
for (int i = 0; i < fields.size(); i++) {
FieldDesc fd = (FieldDesc)fields.get(i);
if (fd.type.equals("B")) { // NOI18N
values.add(new NameValue(fd, new Byte(readByte())));
values.add(new NameValue(fd, readByte()));
} else if (fd.type.equals("S")) { // NOI18N
values.add(new NameValue(fd, new Short(readShort())));
values.add(new NameValue(fd, readShort()));
} else if (fd.type.equals("I")) { // NOI18N
values.add(new NameValue(fd, new Integer(readInt())));
} else if (fd.type.equals("J")) { // NOI18N
Expand All @@ -579,5 +579,4 @@ private List<NameValue> readNoWrClass(ClassDesc cd) throws IOException {
if (DEBUG) System.err.println("readNoWrClass: " + values); // NOI18N
return values;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private Object defaultValue() {
}

if (getConvertedType().equals(Byte.class)) {
value = new Byte((byte) 0);
value = (byte)0;
}

if (getConvertedType().equals(Character.class)) {
Expand All @@ -372,7 +372,7 @@ private Object defaultValue() {
}

if (getConvertedType().equals(Short.class)) {
value = new Short((short) 0);
value = (short)0;
}
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,9 @@ private Object getObject(Object[] params) throws Exception {
try {
switch (index) {
case 0:
return new Byte(value);
return Byte.valueOf(value);
case 1:
return new Short(value);
return Short.valueOf(value);
case 2:
return new Integer(value); //(objI);
case 3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boo
* @param out the stream to serialize to
*/
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(new Short(serialVersion));
out.writeObject(serialVersion);
out.writeInt(closeOperation);
out.writeObject(getName());
out.writeObject(getToolTipText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private Object generateDefaultValue() {
if (type == Integer.class || type == Integer.TYPE) {
return new Integer(0);
} else if (type == Short.class || type == Short.TYPE) {
return new Short((short) 0);
return (short)0;
} else if (type == Long.class || type == Long.TYPE) {
return new Long(0);
} else if (type == Float.class || type == Float.TYPE) {
Expand Down

0 comments on commit ce03e1d

Please sign in to comment.