< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
+ * 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

@@ -157,16 +157,16 @@
         boolean negative = (i < 0);
         if (!negative) {
             i = -i;
         }
         while (i <= -radix) {
-            StringUTF16.putChar(buf, charPos--, Integer.digits[(int)(-(i % radix))]);
+            StringUTF16.Trusted.putChar(buf, charPos--, Integer.digits[(int)(-(i % radix))]);
             i = i / radix;
         }
-        StringUTF16.putChar(buf, charPos, Integer.digits[(int)(-i)]);
+        StringUTF16.Trusted.putChar(buf, charPos, Integer.digits[(int)(-i)]);
         if (negative) {
-            StringUTF16.putChar(buf, --charPos, '-');
+            StringUTF16.Trusted.putChar(buf, --charPos, '-');
         }
         return StringUTF16.newString(buf, charPos, (65 - charPos));
     }
 
     /**

@@ -412,16 +412,16 @@
             val >>>= shift;
         } while (charPos > offset);
     }
 
     /** byte[]/UTF16 version    */
-    static void formatUnsignedLong0UTF16(long val, int shift, byte[] buf, int offset, int len) {
+    private static void formatUnsignedLong0UTF16(long 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[((int) val) & mask]);
+            StringUTF16.Trusted.putChar(buf, --charPos, Integer.digits[((int) val) & mask]);
             val >>>= shift;
         } while (charPos > offset);
     }
 
     static String fastUUID(long lsb, long msb) {

@@ -446,14 +446,14 @@
             formatUnsignedLong0UTF16(lsb >>> 48, 4, buf, 19, 4);
             formatUnsignedLong0UTF16(msb,        4, buf, 14, 4);
             formatUnsignedLong0UTF16(msb >>> 16, 4, buf, 9,  4);
             formatUnsignedLong0UTF16(msb >>> 32, 4, buf, 0,  8);
 
-            StringUTF16.putChar(buf, 23, '-');
-            StringUTF16.putChar(buf, 18, '-');
-            StringUTF16.putChar(buf, 13, '-');
-            StringUTF16.putChar(buf,  8, '-');
+            StringUTF16.Trusted.putChar(buf, 23, '-');
+            StringUTF16.Trusted.putChar(buf, 18, '-');
+            StringUTF16.Trusted.putChar(buf, 13, '-');
+            StringUTF16.Trusted.putChar(buf,  8, '-');
 
             return new String(buf, UTF16);
         }
     }
 

@@ -473,11 +473,11 @@
             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);
+            StringUTF16.Trusted.getChars(i, size, buf);
             return new String(buf, UTF16);
         }
     }
 
     /**

@@ -560,65 +560,10 @@
         }
         return charPos;
     }
 
     /**
-     * This is a variant of {@link #getChars(long, 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(long i, int index, byte[] buf) {
-        long q;
-        int r;
-        int charPos = index;
-
-        boolean negative = (i < 0);
-        if (!negative) {
-            i = -i;
-        }
-
-        // Get 2 digits/iteration using longs until quotient fits into an int
-        while (i <= Integer.MIN_VALUE) {
-            q = i / 100;
-            r = (int)((q * 100) - i);
-            i = q;
-            StringUTF16.putChar(buf, --charPos, Integer.DigitOnes[r]);
-            StringUTF16.putChar(buf, --charPos, Integer.DigitTens[r]);
-        }
-
-        // Get 2 digits/iteration using ints
-        int q2;
-        int i2 = (int)i;
-        while (i2 <= -100) {
-            q2 = i2 / 100;
-            r  = (q2 * 100) - i2;
-            i2 = q2;
-            StringUTF16.putChar(buf, --charPos, Integer.DigitOnes[r]);
-            StringUTF16.putChar(buf, --charPos, Integer.DigitTens[r]);
-        }
-
-        // We know there are at most two digits left at this point.
-        q2 = i2 / 10;
-        r  = (q2 * 10) - i2;
-        StringUTF16.putChar(buf, --charPos, '0' + r);
-
-        // Whatever left is the remaining digit.
-        if (q2 < 0) {
-            StringUTF16.putChar(buf, --charPos, '0' - q2);
-        }
-
-        if (negative) {
-            StringUTF16.putChar(buf, --charPos, '-');
-        }
-        return charPos;
-    }
-
-    /**
      * Returns the string representation size for a given long value.
      *
      * @param x long value
      * @return string size
      *
< prev index next >