Stop memoizing Label#hashCode()

Both members of Label (String & PackageIdentifier) have memoized hash codes so
this should be marginally more expensive but probably not noticably so. The
benefit is it makes Label objects smaller in certain vm conditions.

As to why things were the way they were, I believe this is from before
PackageIdentifier memoized its hashCode.

RELNOTES: None
PiperOrigin-RevId: 181362077
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
index caa5c5e..47a7d7b 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
@@ -35,6 +35,7 @@
 import java.io.InvalidObjectException;
 import java.io.ObjectInputStream;
 import java.io.Serializable;
+import java.util.Arrays;
 import javax.annotation.Nullable;
 
 /**
@@ -276,22 +277,12 @@
   /** The name of the target within the package. Canonical. */
   private final String name;
 
-  /** Precomputed hash code. */
-  private final int hashCode;
-
   private Label(PackageIdentifier packageIdentifier, String name) {
     Preconditions.checkNotNull(packageIdentifier);
     Preconditions.checkNotNull(name);
 
     this.packageIdentifier = packageIdentifier;
     this.name = name;
-    this.hashCode = hashCode(this.name, this.packageIdentifier);
-  }
-
-  /** A specialization of Arrays.HashCode() that does not require constructing a 2-element array. */
-  private static final int hashCode(Object obj1, Object obj2) {
-    int result = 31 + (obj1 == null ? 0 : obj1.hashCode());
-    return 31 * result + (obj2 == null ? 0 : obj2.hashCode());
   }
 
   private Object writeReplace() {
@@ -527,7 +518,7 @@
 
   @Override
   public int hashCode() {
-    return hashCode;
+    return hashCode(name, packageIdentifier);
   }
 
   /** Two labels are equal iff both their name and their package name are equal. */
@@ -538,8 +529,7 @@
     }
     Label otherLabel = (Label) other;
     // Perform the equality comparisons in order from least likely to most likely.
-    return hashCode == otherLabel.hashCode
-        && name.equals(otherLabel.name)
+    return name.equals(otherLabel.name)
         && packageIdentifier.equals(otherLabel.packageIdentifier);
   }
 
@@ -582,4 +572,13 @@
   public void str(SkylarkPrinter printer) {
     printer.append(getCanonicalForm());
   }
+
+  /**
+   * Specialization of {@link Arrays#hashCode()} that does not require constructing a 2-element
+   * array.
+   */
+  private static final int hashCode(Object obj1, Object obj2) {
+    int result = 31 + (obj1 == null ? 0 : obj1.hashCode());
+    return 31 * result + (obj2 == null ? 0 : obj2.hashCode());
+  }
 }