MCPcopy Create free account
hub / github.com/antlr/codebuff / intern

Method intern

output/java_guava/1.4.19/Interners.java:72–96  ·  view source on GitHub ↗
(E sample)

Source from the content-addressed store, hash-verified

70 private final MapMakerInternalMap<E, Dummy> map = new MapMaker().weakKeys().keyEquivalence(Equivalence.equals()).makeCustomMap();
71
72 @Override
73 public E intern(E sample) {
74 while (true) {
75 // trying to read the canonical...
76 ReferenceEntry<E, Dummy> entry = map.getEntry(sample);
77 if (entry != null) {
78 E canonical = entry.getKey();
79 if (canonical != null) { // only matters if weak/soft keys are used
80 return canonical;
81 }
82 }
83
84 // didn't see it, trying to put it instead...
85 Dummy sneaky = map.putIfAbsent(sample, Dummy.VALUE);
86 if (sneaky == null) {
87 return sample;
88 } else {
89 /* Someone beat us to it! Trying again...
90 *
91 * Technically this loop not guaranteed to terminate, so theoretically (extremely
92 * unlikely) this thread might starve, but even then, there is always going to be another
93 * thread doing progress here.
94 */}
95 }
96 }
97
98 private enum Dummy {
99 VALUE

Callers

nothing calls this directly

Calls 3

getEntryMethod · 0.65
getKeyMethod · 0.65
putIfAbsentMethod · 0.45

Tested by

no test coverage detected