Skip to content

Commit

Permalink
Avoid allocations from varargs arrays and boxing in `BzlLoadValue.Key…
Browse files Browse the repository at this point in the history
…` hashcodes.

PiperOrigin-RevId: 676849257
Change-Id: Iea560a9bbfffe2c5cfaaf6d467d1c6edaf49a996
  • Loading branch information
justinhorvitz authored and copybara-github committed Sep 20, 2024
1 parent b018aae commit 03f3b25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2664,6 +2664,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/packages:bzl_visibility",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization",
"//src/main/java/com/google/devtools/build/lib/util:hash_codes",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//src/main/java/net/starlark/java/eval",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.devtools.build.lib.skyframe.serialization.LeafSerializationContext;
import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization;
import com.google.devtools.build.lib.util.HashCodes;
import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.SkyFunctionName;
Expand All @@ -39,7 +40,6 @@
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import java.io.IOException;
import java.util.Objects;
import net.starlark.java.eval.Module;

/**
Expand Down Expand Up @@ -190,7 +190,10 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return Objects.hash(getClass(), getLabel(), isBuildPrelude(), isBuiltins());
int result = HashCodes.hashObjects(getClass(), getLabel());
result = 31 * result + Boolean.hashCode(isBuildPrelude());
result = 31 * result + Boolean.hashCode(isBuiltins());
return result;
}

protected final MoreObjects.ToStringHelper toStringHelper() {
Expand Down Expand Up @@ -316,7 +319,10 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), workspaceChunk, workspacePath);
int result = super.hashCode();
result = 31 * result + Integer.hashCode(workspaceChunk);
result = 31 * result + workspacePath.hashCode();
return result;
}
}

Expand Down

0 comments on commit 03f3b25

Please sign in to comment.