Refactor all ctor callsites of PathFragment to instead call a static 'create' method.
This paves the way for changing PathFragment to e.g. an abstract class with multiple subclasses. This way we can split out the windows-specific stuff into one of these concrete classes, making the code more readable and also saving memory (since the shallow heap size of the NonWindowsPathFragment subclass will hopefully be smaller than that of the current PathFragment).
This also lets us pursue gc churn optimizations. We can now do interning in PathFragment#create and can also get rid of unnecessary intermediate PathFragment allocations.
RELNOTES: None
PiperOrigin-RevId: 152145768
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
index c729fc6..21afd0a 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
@@ -389,11 +389,11 @@
}
private Artifact createSourceArtifact(String path) {
- return new Artifact(new PathFragment(path), Root.asSourceRoot(root));
+ return new Artifact(PathFragment.create(path), Root.asSourceRoot(root));
}
private Artifact createDerivedArtifact(String path) {
- PathFragment execPath = new PathFragment("out").getRelative(path);
+ PathFragment execPath = PathFragment.create("out").getRelative(path);
Path fullPath = root.getRelative(execPath);
Artifact output =
new Artifact(
@@ -416,7 +416,7 @@
}
private Artifact createDerivedTreeArtifactOnly(String path) {
- PathFragment execPath = new PathFragment("out").getRelative(path);
+ PathFragment execPath = PathFragment.create("out").getRelative(path);
Path fullPath = root.getRelative(execPath);
return new SpecialArtifact(
fullPath,
@@ -429,7 +429,7 @@
private TreeFileArtifact createFakeTreeFileArtifact(Artifact treeArtifact,
String parentRelativePath, String content) throws Exception {
TreeFileArtifact treeFileArtifact = ActionInputHelper.treeFileArtifact(
- treeArtifact, new PathFragment(parentRelativePath));
+ treeArtifact, PathFragment.create(parentRelativePath));
Path path = treeFileArtifact.getPath();
FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
writeFile(path, content);
@@ -499,9 +499,9 @@
try {
if (output.isTreeArtifact()) {
TreeFileArtifact treeFileArtifact1 = ActionInputHelper.treeFileArtifact(
- output, new PathFragment("child1"));
+ output, PathFragment.create("child1"));
TreeFileArtifact treeFileArtifact2 = ActionInputHelper.treeFileArtifact(
- output, new PathFragment("child2"));
+ output, PathFragment.create("child2"));
TreeArtifactValue treeArtifactValue = TreeArtifactValue.create(ImmutableMap.of(
treeFileArtifact1, FileArtifactValue.create(treeFileArtifact1),
treeFileArtifact2, FileArtifactValue.create(treeFileArtifact2)));