@@ -197,7 +197,7 @@ object Names {
197
197
private final val fillFactor = 0.7
198
198
199
199
/** Memory to store all names sequentially. */
200
- private var chrs : Array [Char ] = new Array [Char ](InitialNameSize )
200
+ var chrs : Array [Char ] = new Array [Char ](InitialNameSize )
201
201
202
202
/** The number of characters filled. */
203
203
private var nc = 0
@@ -287,6 +287,36 @@ object Names {
287
287
}
288
288
}
289
289
290
+ /**
291
+ * Used only by the GenBCode backend, to represent bytecode-level types in a way that makes equals() and hashCode() efficient.
292
+ * For bytecode-level types of OBJECT sort, its internal name (not its descriptor) is stored.
293
+ * For those of ARRAY sort, its descriptor is stored ie has a leading '['
294
+ * For those of METHOD sort, its descriptor is stored ie has a leading '('
295
+ *
296
+ * can-multi-thread
297
+ * TODO SI-6240 !!! JZ Really? the constructors TermName and TypeName publish unconstructed `this` references
298
+ * into the hash tables; we could observe them here before the subclass constructor completes.
299
+ */
300
+ final def lookupTypeName (cs : Array [Char ]): TypeName = lookupTypeNameIfExisting(cs, true )
301
+
302
+ final def lookupTypeNameIfExisting (cs : Array [Char ], failOnNotFound : Boolean ): TypeName = {
303
+ val h = hashValue(cs, 0 , cs.length) & (table.size - 1 )
304
+ synchronized {
305
+ val next = table(h)
306
+ var name = next
307
+ while (name ne null ) {
308
+ if (name.length == len && equals(name.start, cs, 0 , cs.length))
309
+ return name.toTypeName
310
+ name = name.next
311
+ }
312
+ if (failOnNotFound) {
313
+ throw new RuntimeException (s " lookup of non-existing TypeName: ${new String (cs)}" )
314
+ } else {
315
+ return null
316
+ }
317
+ }
318
+ }
319
+
290
320
/** Create a type name from the characters in cs[offset..offset+len-1].
291
321
* Assume they are already encoded.
292
322
*/
0 commit comments