diff options
author | Piotr Jastrzebski <haaawk@google.com> | 2015-03-04 19:14:48 +0000 |
---|---|---|
committer | Piotr Jastrzebski <haaawk@google.com> | 2015-03-23 16:10:41 +0000 |
commit | 83b7be6b15e433f8594bb62dd1dc5115300709f3 (patch) | |
tree | e70a992a5ee0921594d8f5a456c1bc64213265f6 /sched/src/com/android/sched | |
parent | 9ecf4b02965abc736a1fa94c1cb11e564c45717b (diff) | |
download | toolchain_jack-83b7be6b15e433f8594bb62dd1dc5115300709f3.tar.gz toolchain_jack-83b7be6b15e433f8594bb62dd1dc5115300709f3.tar.bz2 toolchain_jack-83b7be6b15e433f8594bb62dd1dc5115300709f3.zip |
Optimize VPathFragment creation.
When compiling Music app we create 207k instances of VPathFragment.
83k of them are created in VPath.appendPath and VPath.prependPath.
Those instances are the same so this change introduces a new static
field to VPath which will keep a singleton for all those invocations.
The remaining 124k instances are created in VPath constructor and have
the same separator (INTERNAL_SEPARATOR). This change introduces a new
subclass of VPathFragment to handle separators different than
INTERNAL_SEPARATOR. VPathFragment itself assumes INTERNAL_SEPARATOR is
used. This way we make those 124k objects smaller and save on GC.
Change-Id: Ic69c6c2bcf72473ea71a2d7d0adc1bfb5dc5bbd7
Diffstat (limited to 'sched/src/com/android/sched')
-rw-r--r-- | sched/src/com/android/sched/vfs/VPath.java | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/sched/src/com/android/sched/vfs/VPath.java b/sched/src/com/android/sched/vfs/VPath.java index e18c32b7..a84ab0e9 100644 --- a/sched/src/com/android/sched/vfs/VPath.java +++ b/sched/src/com/android/sched/vfs/VPath.java @@ -34,6 +34,8 @@ public final class VPath implements Cloneable { public static final VPath ROOT = new VPath("", '/'); private static final char INTERNAL_SEPARATOR = '/'; + private static final VPathFragment INTERNAL_SEPARATOR_FRAGMENT = + new VPathFragment(String.valueOf(INTERNAL_SEPARATOR), INTERNAL_SEPARATOR); @Nonnull private static final Splitter splitter = Splitter.on(INTERNAL_SEPARATOR).omitEmptyStrings(); @@ -70,8 +72,7 @@ public final class VPath implements Cloneable { public VPath prependPath(@Nonnull VPath path) { assert !path.isRoot(); if (!this.isRoot()) { - pathFragments.add(0, - new VPathFragment(String.valueOf(INTERNAL_SEPARATOR), INTERNAL_SEPARATOR)); + pathFragments.add(0, INTERNAL_SEPARATOR_FRAGMENT); } pathFragments.addAll(0, path.getPathFragments()); @@ -87,7 +88,7 @@ public final class VPath implements Cloneable { public VPath appendPath(@Nonnull VPath path) { assert !path.isRoot(); if (!this.isRoot()) { - pathFragments.add(new VPathFragment(String.valueOf(INTERNAL_SEPARATOR), INTERNAL_SEPARATOR)); + pathFragments.add(INTERNAL_SEPARATOR_FRAGMENT); } pathFragments.addAll(path.getPathFragments()); @@ -179,7 +180,7 @@ public final class VPath implements Cloneable { /** * A portion of path that should be immutable. */ - static class VPathFragment { + private static class VPathFragment { @Nonnull private final CharSequence path; @@ -213,7 +214,7 @@ public final class VPath implements Cloneable { } private boolean isValidSuffix() { - return !path.toString().contains(String.valueOf(separator)); + return path.toString().indexOf(separator) == -1; } } |