mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8267844: Replace Integer/Long.valueOf() with Integer/Long.parse*() where applicable
Reviewed-by: redestad
This commit is contained in:
parent
d38b31438d
commit
b29fbad940
6 changed files with 31 additions and 13 deletions
|
@ -201,8 +201,7 @@ final class CipherCore {
|
|||
if (mode.length() > offset) {
|
||||
int numInt;
|
||||
try {
|
||||
Integer num = Integer.valueOf(mode.substring(offset));
|
||||
numInt = num.intValue();
|
||||
numInt = Integer.parseInt(mode.substring(offset));
|
||||
result = numInt >> 3;
|
||||
} catch (NumberFormatException e) {
|
||||
throw new NoSuchAlgorithmException
|
||||
|
|
|
@ -1413,7 +1413,7 @@ public final class Integer extends Number
|
|||
int radix = 10;
|
||||
int index = 0;
|
||||
boolean negative = false;
|
||||
Integer result;
|
||||
int result;
|
||||
|
||||
if (nm.isEmpty())
|
||||
throw new NumberFormatException("Zero length string");
|
||||
|
@ -1443,15 +1443,15 @@ public final class Integer extends Number
|
|||
throw new NumberFormatException("Sign character in wrong position");
|
||||
|
||||
try {
|
||||
result = Integer.valueOf(nm.substring(index), radix);
|
||||
result = negative ? Integer.valueOf(-result.intValue()) : result;
|
||||
result = parseInt(nm, index, nm.length(), radix);
|
||||
result = negative ? -result : result;
|
||||
} catch (NumberFormatException e) {
|
||||
// If number is Integer.MIN_VALUE, we'll end up here. The next line
|
||||
// handles this case, and causes any genuine format error to be
|
||||
// rethrown.
|
||||
String constant = negative ? ("-" + nm.substring(index))
|
||||
: nm.substring(index);
|
||||
result = Integer.valueOf(constant, radix);
|
||||
result = parseInt(constant, radix);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1254,7 +1254,7 @@ public final class Long extends Number
|
|||
int radix = 10;
|
||||
int index = 0;
|
||||
boolean negative = false;
|
||||
Long result;
|
||||
long result;
|
||||
|
||||
if (nm.isEmpty())
|
||||
throw new NumberFormatException("Zero length string");
|
||||
|
@ -1284,15 +1284,15 @@ public final class Long extends Number
|
|||
throw new NumberFormatException("Sign character in wrong position");
|
||||
|
||||
try {
|
||||
result = Long.valueOf(nm.substring(index), radix);
|
||||
result = negative ? Long.valueOf(-result.longValue()) : result;
|
||||
result = parseLong(nm, index, nm.length(), radix);
|
||||
result = negative ? -result : result;
|
||||
} catch (NumberFormatException e) {
|
||||
// If number is Long.MIN_VALUE, we'll end up here. The next line
|
||||
// handles this case, and causes any genuine format error to be
|
||||
// rethrown.
|
||||
String constant = negative ? ("-" + nm.substring(index))
|
||||
: nm.substring(index);
|
||||
result = Long.valueOf(constant, radix);
|
||||
result = parseLong(constant, radix);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -272,8 +272,8 @@ public class VM {
|
|||
s = props.get("java.class.version");
|
||||
int index = s.indexOf('.');
|
||||
try {
|
||||
classFileMajorVersion = Integer.valueOf(s.substring(0, index));
|
||||
classFileMinorVersion = Integer.valueOf(s.substring(index+1, s.length()));
|
||||
classFileMajorVersion = Integer.parseInt(s.substring(0, index));
|
||||
classFileMinorVersion = Integer.parseInt(s.substring(index + 1));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InternalError(e);
|
||||
}
|
||||
|
|
|
@ -76,6 +76,13 @@ public class Integers {
|
|||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void decode(Blackhole bh) {
|
||||
for (String s : strings) {
|
||||
bh.consume(Integer.decode(s));
|
||||
}
|
||||
}
|
||||
|
||||
/** Performs toString on small values, just a couple of digits. */
|
||||
@Benchmark
|
||||
public void toStringSmall(Blackhole bh) {
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.openjdk.jmh.annotations.State;
|
|||
import org.openjdk.jmh.annotations.Warmup;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
|
@ -48,16 +49,20 @@ public class Longs {
|
|||
@Param("500")
|
||||
private int size;
|
||||
|
||||
private String[] strings;
|
||||
private long[] longArraySmall;
|
||||
private long[] longArrayBig;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
var random = ThreadLocalRandom.current();
|
||||
strings = new String[size];
|
||||
longArraySmall = new long[size];
|
||||
longArrayBig = new long[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
strings[i] = "" + (random.nextLong(10000) - 5000);
|
||||
longArraySmall[i] = 100L * i + i + 103L;
|
||||
longArrayBig[i] = ((100L * i + i) << 32) + 4543 + i * 4;
|
||||
longArrayBig[i] = ((100L * i + i) << 32) + 4543 + i * 4L;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,6 +74,13 @@ public class Longs {
|
|||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void decode(Blackhole bh) {
|
||||
for (String s : strings) {
|
||||
bh.consume(Long.decode(s));
|
||||
}
|
||||
}
|
||||
|
||||
/** Performs toString on large values, around 10 digits. */
|
||||
@Benchmark
|
||||
public void toStringBig(Blackhole bh) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue