Don't intern PathFragments when we create PackageIdentifiers. This should be a strict win:
There are only two places Canonicalizer did PathFragment interning: PackageIdentifier creation and Package creation. PackageIdentifiers are always interned by a separate interner, and so the underlying PathFragment will be in 1-1 correspondence with PackageIdentifiers (per repo). Moreover, Packages are created with a PackageIdentifier already existing, so it will use the same PathFragment of the unique PackageIdentifier.
PiperOrigin-RevId: 185877942
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
index e763fc9..fdf574f 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
@@ -21,7 +21,6 @@
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
-import com.google.devtools.build.lib.vfs.Canonicalizer;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.Serializable;
import java.util.Objects;
@@ -115,7 +114,7 @@
private PackageIdentifier(RepositoryName repository, PathFragment pkgName) {
this.repository = Preconditions.checkNotNull(repository);
- this.pkgName = Canonicalizer.fragments().intern(Preconditions.checkNotNull(pkgName));
+ this.pkgName = Preconditions.checkNotNull(pkgName);
this.hashCode = Objects.hash(repository, pkgName);
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java
index 0f11326..4f81512 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Package.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java
@@ -41,7 +41,6 @@
import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
import com.google.devtools.build.lib.syntax.SkylarkSemantics;
import com.google.devtools.build.lib.util.SpellChecker;
-import com.google.devtools.build.lib.vfs.Canonicalizer;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
@@ -222,7 +221,7 @@
protected Package(PackageIdentifier packageId, String runfilesPrefix) {
this.packageIdentifier = packageId;
this.workspaceName = runfilesPrefix;
- this.nameFragment = Canonicalizer.fragments().intern(packageId.getPackageFragment());
+ this.nameFragment = packageId.getPackageFragment();
this.name = nameFragment.getPathString();
}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/BUILD b/src/main/java/com/google/devtools/build/lib/vfs/BUILD
index b829858..442a7a3 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/vfs/BUILD
@@ -7,7 +7,6 @@
)
PATH_FRAGMENT_SOURCES = [
- "Canonicalizer.java",
"PathFragment.java",
"PathFragmentSerializationProxy.java",
"OsPathPolicy.java",
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Canonicalizer.java b/src/main/java/com/google/devtools/build/lib/vfs/Canonicalizer.java
deleted file mode 100644
index 5243c0b..0000000
--- a/src/main/java/com/google/devtools/build/lib/vfs/Canonicalizer.java
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.vfs;
-
-import com.google.common.collect.Interner;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
-
-/**
- * Static singleton holder for certain interning pools.
- */
-public final class Canonicalizer<E> {
-
- private static final Interner<PathFragment> FRAGMENT_INTERNER =
- BlazeInterners.newWeakInterner();
-
- /**
- * Creates an instance of Canonicalizer tracking path fragments.
- */
- public static Interner<PathFragment> fragments() {
- return FRAGMENT_INTERNER;
- }
-
- private Canonicalizer() {
- }
-}