diff options
author | Neil Fuller <nfuller@google.com> | 2014-03-26 16:59:44 +0000 |
---|---|---|
committer | Neil Fuller <nfuller@google.com> | 2014-03-28 11:19:46 +0000 |
commit | 08da684abe6d5515a9c760a3a33af4f8b426095d (patch) | |
tree | ab1d757261bc97a6b64cb68c4d6c232ec901b4b4 /dex/src/main/java/com/android | |
parent | f9901b2d274fdc2aab890c1e51e09042605b1370 (diff) | |
download | libcore-08da684abe6d5515a9c760a3a33af4f8b426095d.zip libcore-08da684abe6d5515a9c760a3a33af4f8b426095d.tar.gz libcore-08da684abe6d5515a9c760a3a33af4f8b426095d.tar.bz2 |
Improve the performance of Annotation checks
In the circumstance where the annotated element (field/
method/constructor/class) was loaded from a different Dex file
than the annotation:
The previous code would perform a binary
search to determine the type ID of the annotation in the Dex
file of the annotated element. That type ID would then be
compared against the type IDs of annotations present on the
annotated element. The binary search was quite expensive: it
involved various indirections, many small native method calls
and temporary String creation.
Instead, the code now compares the names of the
annotations on the annotated element with the name of the
annotation being searched for. The name of the annotation
is known and cached on the class and is therefore cheap to
get. The name was previously being used to binary search for
the type ID so this appears to be no less correct.
Also removed some unused methods in order to delete the
getFieldIndex() method.
Change-Id: Ib8fb021ddf1221e3eac983aa87e7aea8174720ef
Diffstat (limited to 'dex/src/main/java/com/android')
-rw-r--r-- | dex/src/main/java/com/android/dex/Dex.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/dex/src/main/java/com/android/dex/Dex.java b/dex/src/main/java/com/android/dex/Dex.java index 116a33c..78ee574 100644 --- a/dex/src/main/java/com/android/dex/Dex.java +++ b/dex/src/main/java/com/android/dex/Dex.java @@ -882,7 +882,7 @@ public final class Dex { /** * Returns the number of bytes used by this section. */ - public int used () { + public int used() { return data.position() - initialPosition; } } @@ -896,7 +896,7 @@ public final class Dex { @Override public int size() { return tableOfContents.stringIds.size; } - }; + } private final class TypeIndexToDescriptorIndexTable extends AbstractList<Integer> implements RandomAccess { @@ -906,7 +906,7 @@ public final class Dex { @Override public int size() { return tableOfContents.typeIds.size; } - }; + } private final class TypeIndexToDescriptorTable extends AbstractList<String> implements RandomAccess { @@ -916,7 +916,7 @@ public final class Dex { @Override public int size() { return tableOfContents.typeIds.size; } - }; + } private final class ProtoIdTable extends AbstractList<ProtoId> implements RandomAccess { @Override public ProtoId get(int index) { @@ -927,7 +927,7 @@ public final class Dex { @Override public int size() { return tableOfContents.protoIds.size; } - }; + } private final class FieldIdTable extends AbstractList<FieldId> implements RandomAccess { @Override public FieldId get(int index) { @@ -938,7 +938,7 @@ public final class Dex { @Override public int size() { return tableOfContents.fieldIds.size; } - }; + } private final class MethodIdTable extends AbstractList<MethodId> implements RandomAccess { @Override public MethodId get(int index) { @@ -949,7 +949,7 @@ public final class Dex { @Override public int size() { return tableOfContents.methodIds.size; } - }; + } private final class ClassDefIterator implements Iterator<ClassDef> { private final Dex.Section in = open(tableOfContents.classDefs.off); @@ -971,7 +971,7 @@ public final class Dex { public void remove() { throw new UnsupportedOperationException(); } - }; + } private final class ClassDefIterable implements Iterable<ClassDef> { public Iterator<ClassDef> iterator() { @@ -979,5 +979,5 @@ public final class Dex { ? Collections.<ClassDef>emptySet().iterator() : new ClassDefIterator(); } - }; + } } |