mirror of
https://github.com/corda/corda.git
synced 2025-01-07 13:38:47 +00:00
make Long.parseLong more efficient
This commit is contained in:
parent
9017b5996a
commit
e0e827596e
@ -128,15 +128,19 @@ public final class Long extends Number implements Comparable<Long> {
|
||||
int i = 0;
|
||||
long number = 0;
|
||||
boolean negative = s.startsWith("-");
|
||||
int length = s.length();
|
||||
if (negative) {
|
||||
i = 1;
|
||||
-- length;
|
||||
}
|
||||
|
||||
long factor = pow(radix, length - 1);
|
||||
for (; i < s.length(); ++i) {
|
||||
char c = s.charAt(i);
|
||||
int digit = Character.digit(c, radix);
|
||||
if (digit >= 0) {
|
||||
number += digit * pow(radix, (s.length() - i - 1));
|
||||
number += digit * factor;
|
||||
factor /= radix;
|
||||
} else {
|
||||
throw new NumberFormatException("invalid character " + c + " code " +
|
||||
(int) c);
|
||||
|
@ -102,6 +102,10 @@ public class Misc {
|
||||
expect(foo > 0);
|
||||
}
|
||||
|
||||
expect(Long.parseLong("25214903884") == 25214903884L);
|
||||
|
||||
expect(Long.parseLong("-9223372036854775808") == -9223372036854775808L);
|
||||
|
||||
expect(String.valueOf(25214903884L).equals("25214903884"));
|
||||
|
||||
expect(String.valueOf(-9223372036854775808L).equals
|
||||
|
Loading…
Reference in New Issue
Block a user