diff options
author | nharmata <nharmata@google.com> | 2017-04-04 17:11:39 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2017-04-05 15:18:20 +0200 |
commit | b4060b6e53944a7c3bdc5e62b288e7293a87652a (patch) | |
tree | 59b0f1f3d3e8e99412e060bb98b5a37fe90d9b6e /src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java | |
parent | 3ac77cb94a4cf1bd1993a97fe79f2005b2b1a711 (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java index 9cc3dc78d8..5b3bc1e717 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java @@ -109,7 +109,7 @@ public class FileSystemUtils { */ public static PathFragment relativePath(PathFragment fromDir, PathFragment to) { if (to.equals(fromDir)) { - return new PathFragment("."); // same dir, just return '.' + return PathFragment.create("."); // same dir, just return '.' } if (to.startsWith(fromDir)) { return to.relativeTo(fromDir); // easy case--it's a descendant @@ -123,7 +123,7 @@ public class FileSystemUtils { for (int i = 0; i < levels; i++) { dotdots.append("../"); } - return new PathFragment(dotdots.toString()).getRelative(to.relativeTo(ancestor)); + return PathFragment.create(dotdots.toString()).getRelative(to.relativeTo(ancestor)); } /** @@ -229,9 +229,10 @@ public class FileSystemUtils { int count = path.segmentCount(); for (int i = 0; i < count; i++) { if (path.getSegment(i).equals(oldSegment)) { - path = new PathFragment(path.subFragment(0, i), - new PathFragment(newSegment), - path.subFragment(i+1, count)); + path = PathFragment.create( + path.subFragment(0, i), + PathFragment.create(newSegment), + path.subFragment(i+1, count)); if (!replaceAll) { return path; } @@ -287,7 +288,7 @@ public class FileSystemUtils { * 'user.dir'. This version does not require a {@link FileSystem}. */ public static PathFragment getWorkingDirectory() { - return new PathFragment(System.getProperty("user.dir", "/")); + return PathFragment.create(System.getProperty("user.dir", "/")); } /**************************************************************************** @@ -356,7 +357,7 @@ public class FileSystemUtils { */ @ThreadSafe // but not atomic public static void ensureSymbolicLink(Path link, String target) throws IOException { - ensureSymbolicLink(link, new PathFragment(target)); + ensureSymbolicLink(link, PathFragment.create(target)); } /** |