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 |
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 */ |
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) { |
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 |
|
} |