BUG-7996: Use weak keys in SharedJSONCodecFactory 88/53388/7
authorRobert Varga <rovarga@cisco.com>
Thu, 16 Mar 2017 08:34:42 +0000 (09:34 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 23 Mar 2017 09:26:57 +0000 (10:26 +0100)
This speeds up hashing, as weak keys are forcing identity-based
hashCode/equals().

Change-Id: If6b0323ac8e80fc8833a13ff5b4406e908e7f558
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/SharedJSONCodecFactory.java

index 8cf405860cf3348c08ece120f46339380de466b3..b7c1f4037fe99d16576563fdc30c75bffa7109ab 100644 (file)
@@ -31,8 +31,9 @@ final class SharedJSONCodecFactory extends JSONCodecFactory {
                 }
             });
 
+    // Weak keys to force identity lookup
     // Soft values to keep unreferenced codecs around for a bit, but eventually we want them to go away
-    private final LoadingCache<TypedSchemaNode, JSONCodec<?>> codecs = CacheBuilder.newBuilder().softValues()
+    private final LoadingCache<TypedSchemaNode, JSONCodec<?>> codecs = CacheBuilder.newBuilder().weakKeys().softValues()
             .build(new CacheLoader<TypedSchemaNode, JSONCodec<?>>() {
                 @Override
                 public JSONCodec<?> load(@Nonnull final TypedSchemaNode key) {