diff options
author | Ian Rogers <irogers@google.com> | 2013-09-19 02:51:22 -0700 |
---|---|---|
committer | Ian Rogers <irogers@google.com> | 2013-09-21 22:05:00 -0700 |
commit | a6e22fc9b70ebe39abd716ce37450bda935c0fb8 (patch) | |
tree | 2bbdf94c92895e7c2faf1db2e8482bf85906a129 /dex/src | |
parent | 98430d0d75f4cfd40614b77debeb3c8d0abf40df (diff) | |
download | libcore-a6e22fc9b70ebe39abd716ce37450bda935c0fb8.zip libcore-a6e22fc9b70ebe39abd716ce37450bda935c0fb8.tar.gz libcore-a6e22fc9b70ebe39abd716ce37450bda935c0fb8.tar.bz2 |
Avoid computing class def indices.
Bug: 10244719
Also tidy AnnotationAccess.
(cherry-picked from 8b2c0b9abc3f520495f4387ea040132ba85cae69)
Change-Id: I6ec8fd4e36b428d7e16e01d98b7bebc143fac8c3
Conflicts:
libdvm/src/main/java/java/lang/Class.java
Diffstat (limited to 'dex/src')
-rw-r--r-- | dex/src/main/java/com/android/dex/Dex.java | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/dex/src/main/java/com/android/dex/Dex.java b/dex/src/main/java/com/android/dex/Dex.java index 89edf6e..116a33c 100644 --- a/dex/src/main/java/com/android/dex/Dex.java +++ b/dex/src/main/java/com/android/dex/Dex.java @@ -357,6 +357,19 @@ public final class Dex { return Collections.binarySearch(methodIds, methodId); } + public int findClassDefIndexFromTypeIndex(int typeIndex) { + checkBounds(typeIndex, tableOfContents.typeIds.size); + if (!tableOfContents.classDefs.exists()) { + return -1; + } + for (int i = 0; i < tableOfContents.classDefs.size; i++) { + if (typeIndexFromClassDefIndex(i) == typeIndex) { + return i; + } + } + return -1; + } + /** * Look up a field id type index from a field index. Cheaper than: * {@code fieldIds().get(fieldDexIndex).getTypeIndex();} @@ -369,6 +382,16 @@ public final class Dex { } /** + * Look up a method id declaring class index from a method index. Cheaper than: + * {@code methodIds().get(methodIndex).getDeclaringClassIndex();} + */ + public int declaringClassIndexFromMethodIndex(int methodIndex) { + checkBounds(methodIndex, tableOfContents.methodIds.size); + int position = tableOfContents.methodIds.off + (SizeOf.MEMBER_ID_ITEM * methodIndex); + return data.getShort(position) & 0xFFFF; // declaringClassIndex + } + + /** * Look up a method id name index from a method index. Cheaper than: * {@code methodIds().get(methodIndex).getNameIndex();} */ @@ -430,12 +453,63 @@ public final class Dex { * Look up a descriptor index from a type index. Cheaper than: * {@code open(tableOfContents.typeIds.off + (index * SizeOf.TYPE_ID_ITEM)).readInt();} */ - private int descriptorIndexFromTypeIndex(int typeIndex) { + public int descriptorIndexFromTypeIndex(int typeIndex) { checkBounds(typeIndex, tableOfContents.typeIds.size); int position = tableOfContents.typeIds.off + (SizeOf.TYPE_ID_ITEM * typeIndex); return data.getInt(position); } + /** + * Look up a type index index from a class def index. + */ + public int typeIndexFromClassDefIndex(int classDefIndex) { + checkBounds(classDefIndex, tableOfContents.classDefs.size); + int position = tableOfContents.classDefs.off + (SizeOf.CLASS_DEF_ITEM * classDefIndex); + return data.getInt(position); + } + + /** + * Look up a type index index from a class def index. + */ + public int annotationDirectoryOffsetFromClassDefIndex(int classDefIndex) { + checkBounds(classDefIndex, tableOfContents.classDefs.size); + int position = tableOfContents.classDefs.off + (SizeOf.CLASS_DEF_ITEM * classDefIndex); + position += SizeOf.UINT; // type + position += SizeOf.UINT; // accessFlags + position += SizeOf.UINT; // superType + position += SizeOf.UINT; // interfacesOffset + position += SizeOf.UINT; // sourceFileIndex + return data.getInt(position); + } + + /** + * Look up interface types indices from a return type index from a method index. Cheaper than: + * {@code ...getClassDef(classDefIndex).getInterfaces();} + */ + public short[] interfaceTypeIndicesFromClassDefIndex(int classDefIndex) { + checkBounds(classDefIndex, tableOfContents.classDefs.size); + int position = tableOfContents.classDefs.off + (SizeOf.CLASS_DEF_ITEM * classDefIndex); + position += SizeOf.UINT; // type + position += SizeOf.UINT; // accessFlags + position += SizeOf.UINT; // superType + int interfacesOffset = data.getInt(position); + if (interfacesOffset == 0) { + return EMPTY_SHORT_ARRAY; + } + position = interfacesOffset; + int size = data.getInt(position); + if (size <= 0) { + throw new AssertionError("Unexpected interfaces list size: " + size); + } + position += SizeOf.UINT; + short[] types = new short[size]; + for (int i = 0; i < size; i++) { + types[i] = data.getShort(position); + position += SizeOf.USHORT; + } + return types; + } + public final class Section implements ByteInput, ByteOutput { private final String name; private final ByteBuffer data; |