diff options
author | janakr <janakr@google.com> | 2018-04-10 15:16:09 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-10 15:17:20 -0700 |
commit | 2b533aba878698d50525826fd3e40571af87a1b9 (patch) | |
tree | 5e9e04befc6d1f035e8f128e1d35f7d8cd200031 /src/main/java/com/google/devtools/build/lib/skyframe/serialization/AutoRegistry.java | |
parent | 9594f2c454acf71beb4bccdcf4f7e40c83288e51 (diff) |
Add value constants to ObjectCodecRegistry. Value constants are to be used when there may not be a canonical instance of the object we want (or the canonical instance isn't available at registry construction time), but we can reasonably cheaply do value equality comparisons. Strings are a good example.
PiperOrigin-RevId: 192354865
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/serialization/AutoRegistry.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/serialization/AutoRegistry.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/AutoRegistry.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/AutoRegistry.java index 7785493aa5..6c81ccfe92 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/AutoRegistry.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/AutoRegistry.java @@ -21,7 +21,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Ordering; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; /** * A lazy, automatically populated registry. @@ -46,7 +49,7 @@ public class AutoRegistry { private static final ImmutableList<String> EXTERNAL_CLASS_NAMES_TO_REGISTER = ImmutableList.of("java.io.FileNotFoundException", "java.io.IOException"); - private static final ImmutableList<Object> CONSTANTS_TO_REGISTER = + private static final ImmutableList<Object> REFERENCE_CONSTANTS_TO_REGISTER = ImmutableList.of( Predicates.alwaysTrue(), Predicates.alwaysFalse(), @@ -57,6 +60,14 @@ public class AutoRegistry { Comparator.naturalOrder(), Ordering.natural()); + private static final ImmutableList<Object> VALUE_CONSTANTS_TO_REGISTER = + ImmutableList.of( + "", + Boolean.FALSE, + Boolean.TRUE, + Collections.unmodifiableMap(new HashMap<>()), + Collections.unmodifiableList(new ArrayList<>())); + public static ObjectCodecRegistry get() { return SUPPLIER.get(); } @@ -68,8 +79,11 @@ public class AutoRegistry { for (String className : EXTERNAL_CLASS_NAMES_TO_REGISTER) { registry.addClassName(className); } - for (Object constant : CONSTANTS_TO_REGISTER) { - registry.addConstant(constant); + for (Object constant : REFERENCE_CONSTANTS_TO_REGISTER) { + registry.addReferenceConstant(constant); + } + for (Object constant : VALUE_CONSTANTS_TO_REGISTER) { + registry.addValueConstant(constant); } return registry.build(); } catch (IOException | ReflectiveOperationException e) { |