Skip to content

Commit

Permalink
optimized code.
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jul 22, 2017
1 parent 768283f commit 4edd2a4
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/java/com/alibaba/fastjson/util/IOUtils.java
Expand Up @@ -275,36 +275,34 @@ public static void getChars(long i, int index, char[] buf) {
* backwards from there. Will fail if i == Integer.MIN_VALUE
*/
public static void getChars(int i, int index, char[] buf) {
int q, r;
int charPos = index;
int q, r, p = index;
char sign = 0;

if (i < 0) {
sign = '-';
i = -i;
}

// Generate two digits per iteration
while (i >= 65536) {
q = i / 100;
// really: r = i - (q * 100);
r = i - ((q << 6) + (q << 5) + (q << 2));
i = q;
buf[--charPos] = DigitOnes[r];
buf[--charPos] = DigitTens[r];
buf[--p] = DigitOnes[r];
buf[--p] = DigitTens[r];
}

// Fall thru to fast mode for smaller numbers
// assert(i <= 65536, i);
for (;;) {
q = (i * 52429) >>> (16 + 3);
r = i - ((q << 3) + (q << 1)); // r = i-(q*10) ...
buf[--charPos] = digits[r];
buf[--p] = digits[r];
i = q;
if (i == 0) break;
}
if (sign != 0) {
buf[--charPos] = sign;
buf[--p] = sign;
}
}

Expand Down

0 comments on commit 4edd2a4

Please sign in to comment.