diff options
author | tomlu <tomlu@google.com> | 2018-01-19 10:25:19 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-19 10:27:24 -0800 |
commit | e7552c53a5dd65ae496562fc29adecd89e9db5fb (patch) | |
tree | f33fb86896b10777b5652812d161454a2cefbe6c /src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java | |
parent | 26866939e115798cf91d7a02de5417ad81314384 (diff) |
Fix usages of PathFragment segments that will become inefficient.
An upcoming replacement to PathFragment will not have efficient segment semantics, causing code to become unnecessarily inefficient.
RELNOTES: None
PiperOrigin-RevId: 182553098
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java b/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java index f385831862..9db3aa3ada 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java @@ -612,6 +612,20 @@ public abstract class PathFragment } /** + * Returns a new path fragment that is a sub fragment of this one. The sub fragment begins at the + * specified <code>beginIndex</code> segment and contains the rest of the original path fragment. + * + * @param beginIndex the beginning index, inclusive. + * @return the specified sub fragment, never null. + * @exception IndexOutOfBoundsException if the <code>beginIndex</code> is negative, or <code> + * endIndex</code> is larger than the length of this <code>String</code> object, or <code> + * beginIndex</code> is larger than <code>endIndex</code>. + */ + public PathFragment subFragment(int beginIndex) { + return subFragment(beginIndex, segments.length); + } + + /** * Returns true iff the path represented by this object is absolute. * * <p>True both for UNIX-style absolute paths ("/foo") and Windows-style ("C:/foo"). False for a @@ -642,6 +656,10 @@ public abstract class PathFragment // windowsVolume). public abstract char getDriveLetter(); + public boolean isEmpty() { + return segments.length == 0; + } + /** * Returns the number of segments in this path. */ |