aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2018-03-02 17:48:57 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-02 17:51:19 -0800
commit5fb2a487e53cc3d80e3654d5b63d062f7f70588b (patch)
tree82b23b68d09c451a8950468668150acdf89533e9 /src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java
parent46f7106d0b20ae0ba245c3609545600ae379cea4 (diff)
Replace LegacySkyKey by AbstractSkyKey or custom SkyKeys. AbstractSkyKey doesn't save memory in the 32-bit case, but makes it easier for people to see how many SkyKeys we have.
There's some unnecessary interning in tests, but it was easier to copypasta and doesn't harm anything, I think. PiperOrigin-RevId: 187694309
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java
index c74fe4a141..83d909deca 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java
@@ -16,12 +16,15 @@ package com.google.devtools.build.lib.skyframe;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Interner;
+import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException;
import com.google.devtools.build.lib.packages.Package;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.syntax.Environment.Extension;
import com.google.devtools.build.lib.vfs.RootedPath;
-import com.google.devtools.build.skyframe.LegacySkyKey;
+import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import java.util.Map;
@@ -34,24 +37,26 @@ import java.util.Objects;
*/
public class WorkspaceFileValue implements SkyValue {
- /**
- * Argument for the SkyKey to request a WorkspaceFileValue.
- */
+ /** Argument for the SkyKey to request a WorkspaceFileValue. */
@Immutable
- public static class WorkspaceFileKey {
+ @AutoCodec
+ public static class WorkspaceFileKey implements SkyKey {
+ private static final Interner<WorkspaceFileKey> interner = BlazeInterners.newWeakInterner();
+
private final RootedPath path;
private final int idx;
- /**
- * Creates a Key for the WorkspaceFileFunction. The path to the workspace file is specified
- * by {@code path}. This key will ask WorkspaceFileFunction to get the {@code idx+1}-th part of
- * the workspace file (so idx = 0 represents the first part, idx = 1, the second part, etc...).
- */
- public WorkspaceFileKey(RootedPath path, int idx) {
+ private WorkspaceFileKey(RootedPath path, int idx) {
this.path = path;
this.idx = idx;
}
+ @AutoCodec.VisibleForSerialization
+ @AutoCodec.Instantiator
+ static WorkspaceFileKey create(RootedPath path, int idx) {
+ return interner.intern(new WorkspaceFileKey(path, idx));
+ }
+
public RootedPath getPath() {
return path;
}
@@ -61,6 +66,11 @@ public class WorkspaceFileValue implements SkyValue {
}
@Override
+ public SkyFunctionName functionName() {
+ return SkyFunctions.WORKSPACE_FILE;
+ }
+
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -134,8 +144,13 @@ public class WorkspaceFileValue implements SkyValue {
return "<WorkspaceFileValue path=" + path + " idx=" + idx + ">";
}
- static SkyKey key(RootedPath path, int idx) {
- return LegacySkyKey.create(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileKey(path, idx));
+ /**
+ * Creates a Key for the WorkspaceFileFunction. The path to the workspace file is specified by
+ * {@code path}. This key will ask WorkspaceFileFunction to get the {@code idx+1}-th part of the
+ * workspace file (so idx = 0 represents the first part, idx = 1, the second part, etc...).
+ */
+ static WorkspaceFileKey key(RootedPath path, int idx) {
+ return WorkspaceFileKey.create(path, idx);
}
public static SkyKey key(RootedPath path) {