ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/Helpers.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/Helpers.java (file contents):
Revision 1.1 by jsr166, Wed Mar 4 00:22:30 2015 UTC vs.
Revision 1.2 by jsr166, Wed Sep 23 22:09:26 2015 UTC

# Line 10 | Line 10 | import java.util.Collection;
10  
11   /** Shared implementation code for java.util.concurrent. */
12   class Helpers {
13 +    private Helpers() {}                // non-instantiable
14 +
15      /**
16       * An implementation of Collection.toString() suitable for classes
17       * with locks.  Instead of holding a lock for the entire duration of
# Line 63 | Line 65 | class Helpers {
65          }
66          chars[j] = ']';
67          // assert j == chars.length - 1;
68 <        return newStringUnsafe(chars);
68 >        return new String(chars);
69      }
70  
71      /** Optimized form of: key + "=" + val */
# Line 76 | Line 78 | class Helpers {
78          k.getChars(0, klen, chars, 0);
79          chars[klen] = '=';
80          v.getChars(0, vlen, chars, klen + 1);
81 <        return newStringUnsafe(chars);
81 >        return new String(chars);
82      }
83  
84      private static String objectToString(Object x) {
# Line 84 | Line 86 | class Helpers {
86          String s;
87          return (x == null || (s = x.toString()) == null) ? "null" : s;
88      }
87
88    /**
89     * Returns a String containing the contents of chars, which caller
90     * promises will never be modified.
91     */
92    private static String newStringUnsafe(char[] chars) {
93        // If porting to a JDK where sun.misc.SharedSecrets is not
94        // available, modify the code below to simply:
95        // return new String(chars);
96        // TODO: Can we do this more portably?
97        return sun.misc.SharedSecrets.getJavaLangAccess().newStringUnsafe(chars);
98    }
99
89   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines