< prev index next >

src/java.base/share/classes/java/lang/Integer.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 173,189 **** int charPos = 32; if (!negative) { i = -i; } while (i <= -radix) { ! StringUTF16.putChar(buf, charPos--, digits[-(i % radix)]); i = i / radix; } ! StringUTF16.putChar(buf, charPos, digits[-i]); if (negative) { ! StringUTF16.putChar(buf, --charPos, '-'); } return StringUTF16.newString(buf, charPos, (33 - charPos)); } /** --- 173,189 ---- int charPos = 32; if (!negative) { i = -i; } while (i <= -radix) { ! StringUTF16.Trusted.putChar(buf, charPos--, digits[-(i % radix)]); i = i / radix; } ! StringUTF16.Trusted.putChar(buf, charPos, digits[-i]); if (negative) { ! StringUTF16.Trusted.putChar(buf, --charPos, '-'); } return StringUTF16.newString(buf, charPos, (33 - charPos)); } /**
*** 384,399 **** val >>>= shift; } while (charPos > offset); } /** byte[]/UTF16 version */ ! static void formatUnsignedIntUTF16(int val, int shift, byte[] buf, int offset, int len) { int charPos = offset + len; int radix = 1 << shift; int mask = radix - 1; do { ! StringUTF16.putChar(buf, --charPos, Integer.digits[val & mask]); val >>>= shift; } while (charPos > offset); } static final byte[] DigitTens = { --- 384,399 ---- val >>>= shift; } while (charPos > offset); } /** byte[]/UTF16 version */ ! private static void formatUnsignedIntUTF16(int val, int shift, byte[] buf, int offset, int len) { int charPos = offset + len; int radix = 1 << shift; int mask = radix - 1; do { ! StringUTF16.Trusted.putChar(buf, --charPos, Integer.digits[val & mask]); val >>>= shift; } while (charPos > offset); } static final byte[] DigitTens = {
*** 440,450 **** byte[] buf = new byte[size]; getChars(i, size, buf); return new String(buf, LATIN1); } else { byte[] buf = new byte[size * 2]; ! getCharsUTF16(i, size, buf); return new String(buf, UTF16); } } /** --- 440,450 ---- byte[] buf = new byte[size]; getChars(i, size, buf); return new String(buf, LATIN1); } else { byte[] buf = new byte[size * 2]; ! StringUTF16.Trusted.getChars(i, size, buf); return new String(buf, UTF16); } } /**
*** 514,566 **** buf[--charPos] = (byte)'-'; } return charPos; } - /** - * This is a variant of {@link #getChars(int, int, byte[])}, but for - * UTF-16 coder. - * - * @param i value to convert - * @param index next index, after the least significant digit - * @param buf target buffer, UTF16-coded. - * @return index of the most significant digit or minus sign, if present - */ - static int getCharsUTF16(int i, int index, byte[] buf) { - int q, r; - int charPos = index; - - boolean negative = (i < 0); - if (!negative) { - i = -i; - } - - // Get 2 digits/iteration using ints - while (i <= -100) { - q = i / 100; - r = (q * 100) - i; - i = q; - StringUTF16.putChar(buf, --charPos, DigitOnes[r]); - StringUTF16.putChar(buf, --charPos, DigitTens[r]); - } - - // We know there are at most two digits left at this point. - q = i / 10; - r = (q * 10) - i; - StringUTF16.putChar(buf, --charPos, '0' + r); - - // Whatever left is the remaining digit. - if (q < 0) { - StringUTF16.putChar(buf, --charPos, '0' - q); - } - - if (negative) { - StringUTF16.putChar(buf, --charPos, '-'); - } - return charPos; - } - // Left here for compatibility reasons, see JDK-8143900. static final int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE }; /** --- 514,523 ----
< prev index next >