diff options
author | Googler <noreply@google.com> | 2016-07-26 14:29:48 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2016-07-27 11:14:04 +0000 |
commit | 2745f0bafd7d549688480cdee3f021de489c719e (patch) | |
tree | 4bc375688e5af969414b1bc3633dec47e8b1f9d0 /src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java | |
parent | 3cf21261bf756c937551c7d852dbca5c954fc44f (diff) |
Improve resource DataKey serialization perf a bit
Address the TODO about using toString in the
TreeMap comparator by using DataKey#compareTo.
Also, use the entrySet to iterate K-V pairs
instead of calling get(key).
Synthetic benchmark w/ 10000 random keys:
Before: 260ms to serialize
After: 33ms to serialize
Less of a difference when there are few keys.
--
MOS_MIGRATED_REVID=128469407
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java b/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java index 4f953c8bd4..ad3fe2427e 100644 --- a/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java +++ b/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java @@ -13,6 +13,9 @@ // limitations under the License. package com.google.devtools.build.android; +import com.android.ide.common.resources.configuration.FolderConfiguration; +import com.android.ide.common.resources.configuration.ResourceQualifier; +import com.android.resources.ResourceType; import com.google.common.base.Joiner; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; @@ -20,11 +23,6 @@ import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.Iterators; import com.google.common.collect.PeekingIterator; import com.google.devtools.build.android.proto.SerializeFormat; - -import com.android.ide.common.resources.configuration.FolderConfiguration; -import com.android.ide.common.resources.configuration.ResourceQualifier; -import com.android.resources.ResourceType; - import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.InvocationTargetException; @@ -40,7 +38,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; - import javax.annotation.CheckReturnValue; import javax.annotation.concurrent.Immutable; @@ -50,7 +47,7 @@ import javax.annotation.concurrent.Immutable; * Each resource name consists of the resource package, name, type, and qualifiers. */ @Immutable -public class FullyQualifiedName implements DataKey, Comparable<FullyQualifiedName> { +public class FullyQualifiedName implements DataKey { public static final String DEFAULT_PACKAGE = "res-auto"; private static final Joiner DASH_JOINER = Joiner.on('-'); @@ -440,7 +437,11 @@ public class FullyQualifiedName implements DataKey, Comparable<FullyQualifiedNam } @Override - public int compareTo(FullyQualifiedName other) { + public int compareTo(DataKey otherKey) { + if (!(otherKey instanceof FullyQualifiedName)) { + return getKeyType().compareTo(otherKey.getKeyType()); + } + FullyQualifiedName other = (FullyQualifiedName) otherKey; if (!pkg.equals(other.pkg)) { return pkg.compareTo(other.pkg); } @@ -461,6 +462,11 @@ public class FullyQualifiedName implements DataKey, Comparable<FullyQualifiedNam } @Override + public KeyType getKeyType() { + return KeyType.FULL_QUALIFIED_NAME; + } + + @Override public void serializeTo(OutputStream out, int valueSize) throws IOException { toSerializedBuilder().setValueSize(valueSize).build().writeDelimitedTo(out); } |