aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs/Path.java
diff options
context:
space:
mode:
authorGravatar nharmata <nharmata@google.com>2017-04-04 14:42:23 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-04-04 18:38:29 +0200
commit39e659e690228c07b79b49dcde1b21fc0cd14e9a (patch)
tree74fa7ec17dcac5586f89b9f1f2cbbfa901eaa350 /src/main/java/com/google/devtools/build/lib/vfs/Path.java
parentc4134802dd15d6ef5cca6521f6bf6aac395ee2ad (diff)
Restructure Path#getCachedChildPath to make direct method calls without allocating a garbage TranslatedPath object.
RELNOTES: None PiperOrigin-RevId: 152130170
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/Path.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/Path.java46
1 files changed, 14 insertions, 32 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Path.java b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
index cfa3520ce9..e4088416cc 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/Path.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
@@ -54,28 +54,6 @@ public class Path implements Comparable<Path>, Serializable {
/** Filesystem-specific factory for {@link Path} objects. */
public static interface PathFactory {
-
- /**
- * A translated path, i.e. where the parent and name are potentially different from the input.
- *
- * <p>See {@link PathFactory#translatePath} for details.
- */
- public static final class TranslatedPath {
- public final Path parent;
- public final String child;
- public final boolean cacheable;
-
- public TranslatedPath(Path parent, String child, boolean cacheable) {
- this.parent = parent;
- this.child = child;
- this.cacheable = cacheable;
- }
-
- public TranslatedPath(Path parent, String child) {
- this(parent, child, true);
- }
- }
-
/**
* Creates the root of all paths used by a filesystem.
*
@@ -96,13 +74,15 @@ public class Path implements Comparable<Path>, Serializable {
Path createChildPath(Path parent, String childName);
/**
- * Translate the input path in a filesystem-specific way if necessary.
+ * Makes the proper invocation of {@link FileSystem#getCachedChildPathInternal}, doing
+ * filesystem-specific logic if necessary.
*
- * <p>On Unix filesystems this operation is typically idempotent, but on Windows this can be
- * used to translate absolute Unix paths to absolute Windows paths, e.g. "/c" to "C:/" or "/usr"
- * to "C:/tools/msys64/usr".
+ * <p>On Unix filesystems this method merely calls through to {@code
+ * FileSystem.getCachedChildPathInternal(parent, child)}, but on Windows this can be used to
+ * handle the translatation of absolute Unix paths to absolute Windows paths, e.g. "/c" to "C:/"
+ * or "/usr" to "C:/tools/msys64/usr".
*/
- TranslatedPath translatePath(Path parent, String child);
+ Path getCachedChildPathInternal(Path path, String childName);
}
private static FileSystem fileSystemForSerialization;
@@ -316,14 +296,16 @@ public class Path implements Comparable<Path>, Serializable {
* if it doesn't already exist.
*/
private Path getCachedChildPath(String childName) {
- return getCachedChildPath(fileSystem.getPathFactory().translatePath(this, childName));
+ return fileSystem.getPathFactory().getCachedChildPathInternal(this, childName);
}
- private static Path getCachedChildPath(PathFactory.TranslatedPath translated) {
- Path parent = translated.parent;
+ /**
+ * Internal method only intended to be called by {@link PathFactory#getCachedChildPathInternal}.
+ */
+ public static Path getCachedChildPathInternal(Path parent, String childName, boolean cacheable) {
// We get a canonical instance since 'children' is an IdentityHashMap.
- String childName = StringCanonicalizer.intern(translated.child);
- if (!translated.cacheable) {
+ childName = StringCanonicalizer.intern(childName);
+ if (!cacheable) {
// Non-cacheable children won't show up in `children` so applyToChildren won't run for these.
return parent.createChildPath(childName);
}