diff options
author | Benoit Lamarche <benoitlamarche@google.com> | 2015-02-10 19:22:14 +0100 |
---|---|---|
committer | Benoit Lamarche <benoitlamarche@google.com> | 2015-02-10 19:22:14 +0100 |
commit | 7862998ee70c46eec7b13efeed2c23b589b9c6ea (patch) | |
tree | 83c66e1c7c16813811f7de3f31862dea46048761 /sched | |
parent | 83b7ed4501ff36c08104a0848fdcb7712905b8de (diff) | |
download | toolchain_jack-7862998ee70c46eec7b13efeed2c23b589b9c6ea.tar.gz toolchain_jack-7862998ee70c46eec7b13efeed2c23b589b9c6ea.tar.bz2 toolchain_jack-7862998ee70c46eec7b13efeed2c23b589b9c6ea.zip |
Optimize VPath append and prepend
Change-Id: I14b3499b6a31f4598766c7e7ce7fa03905901bcb
Diffstat (limited to 'sched')
-rw-r--r-- | sched/src/com/android/sched/vfs/VPath.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/sched/src/com/android/sched/vfs/VPath.java b/sched/src/com/android/sched/vfs/VPath.java index 0eeae394..e18c32b7 100644 --- a/sched/src/com/android/sched/vfs/VPath.java +++ b/sched/src/com/android/sched/vfs/VPath.java @@ -50,9 +50,11 @@ public final class VPath implements Cloneable { */ public VPath(@Nonnull CharSequence path, char separator) { pathFragments = new ArrayList<VPathFragment>(1); - VPathFragment pe = new VPathFragment(path, separator); - assert pe.isValidPath(); - pathFragments.add(pe); + if (path.length() > 0) { + VPathFragment pe = new VPathFragment(path, separator); + assert pe.isValidPath(); + pathFragments.add(pe); + } } private VPath(ArrayList<VPathFragment> pathFragments) { @@ -66,7 +68,8 @@ public final class VPath implements Cloneable { * @return the current path */ public VPath prependPath(@Nonnull VPath path) { - if (!this.equals(VPath.ROOT)) { + assert !path.isRoot(); + if (!this.isRoot()) { pathFragments.add(0, new VPathFragment(String.valueOf(INTERNAL_SEPARATOR), INTERNAL_SEPARATOR)); } @@ -82,7 +85,8 @@ public final class VPath implements Cloneable { * @return the current path */ public VPath appendPath(@Nonnull VPath path) { - if (!this.equals(VPath.ROOT)) { + assert !path.isRoot(); + if (!this.isRoot()) { pathFragments.add(new VPathFragment(String.valueOf(INTERNAL_SEPARATOR), INTERNAL_SEPARATOR)); } pathFragments.addAll(path.getPathFragments()); @@ -168,6 +172,10 @@ public final class VPath implements Cloneable { return getPathAsString(INTERNAL_SEPARATOR); } + public boolean isRoot() { + return pathFragments.isEmpty(); + } + /** * A portion of path that should be immutable. */ |