From 29f49465ca358613486bd6bc61a1b9a5fa3bd1c1 Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Sat, 19 Sep 2009 03:18:35 +0000 Subject: [PATCH] Use a SparseArray instead of a HashMap, and add get*Count methods to AnnotationDirectoryItem so we can initialize the SparseArrays with the correct capacity git-svn-id: https://smali.googlecode.com/svn/trunk@478 55b6fa8a-2a1e-11de-a435-ffa8d773f76a --- .../jf/baksmali/Adaptors/ClassDefinition.java | 15 +++++++---- .../jf/dexlib/AnnotationDirectoryItem.java | 26 ++++++++++++++++--- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java index eb59178c..ac0400f7 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java @@ -31,6 +31,7 @@ package org.jf.baksmali.Adaptors; import org.jf.dexlib.EncodedValue.EncodedValue; import org.jf.dexlib.*; import org.jf.dexlib.Util.AccessFlags; +import org.jf.dexlib.Util.SparseArray; import org.antlr.stringtemplate.StringTemplate; import org.antlr.stringtemplate.StringTemplateGroup; @@ -41,9 +42,9 @@ public class ClassDefinition { private ClassDefItem classDefItem; private ClassDataItem classDataItem; - private HashMap methodAnnotationsMap = new HashMap(); - private HashMap fieldAnnotationsMap = new HashMap(); - private HashMap parameterAnnotationsMap = new HashMap(); + private SparseArray methodAnnotationsMap; + private SparseArray fieldAnnotationsMap; + private SparseArray parameterAnnotationsMap; public ClassDefinition(StringTemplateGroup stg, ClassDefItem classDefItem) { this.stg = stg; @@ -75,20 +76,24 @@ public class ClassDefinition { return; } + methodAnnotationsMap = new SparseArray(annotationDirectory.getMethodAnnotationCount()); annotationDirectory.iterateMethodAnnotations(new AnnotationDirectoryItem.MethodAnnotationIteratorDelegate() { public void processMethodAnnotations(MethodIdItem method, AnnotationSetItem methodAnnotations) { methodAnnotationsMap.put(method.getIndex(), methodAnnotations); } }); + fieldAnnotationsMap = new SparseArray(annotationDirectory.getFieldAnnotationCount()); annotationDirectory.iterateFieldAnnotations(new AnnotationDirectoryItem.FieldAnnotationIteratorDelegate() { public void processFieldAnnotations(FieldIdItem field, AnnotationSetItem fieldAnnotations) { fieldAnnotationsMap.put(field.getIndex(), fieldAnnotations); } }); - annotationDirectory.iteratParameterAnnotations( - new AnnotationDirectoryItem.ParameterAnnotationIteratorDelegate() { + parameterAnnotationsMap = new SparseArray( + annotationDirectory.getParameterAnnotationCount()); + annotationDirectory.iterateParameterAnnotations( + new AnnotationDirectoryItem.ParameterAnnotationIteratorDelegate() { public void processParameterAnnotations(MethodIdItem method, AnnotationSetRefList parameterAnnotations) { parameterAnnotationsMap.put(method.getIndex(), parameterAnnotations); } diff --git a/dexlib/src/main/java/org/jf/dexlib/AnnotationDirectoryItem.java b/dexlib/src/main/java/org/jf/dexlib/AnnotationDirectoryItem.java index 02ad386b..c03652aa 100644 --- a/dexlib/src/main/java/org/jf/dexlib/AnnotationDirectoryItem.java +++ b/dexlib/src/main/java/org/jf/dexlib/AnnotationDirectoryItem.java @@ -28,12 +28,9 @@ package org.jf.dexlib; -import org.jf.dexlib.EncodedValue.AnnotationEncodedSubValue; -import org.jf.dexlib.Util.ArrayUtils; import org.jf.dexlib.Util.Input; import org.jf.dexlib.Util.AnnotatedOutput; -import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -338,6 +335,13 @@ public class AnnotationDirectoryItem extends Item { void processFieldAnnotations(FieldIdItem field, AnnotationSetItem fieldAnnotations); } + /** + * @return the number of field annotations in this AnnotationDirectoryItem + */ + public int getFieldAnnotationCount() { + return fieldAnnotationFields.length; + } + /** * Iterates over the method annotations, calling delegate.processMethodAnnotations for each * @param delegate the delegate to call @@ -352,11 +356,18 @@ public class AnnotationDirectoryItem extends Item { void processMethodAnnotations(MethodIdItem method, AnnotationSetItem methodAnnotations); } + /** + * @return the number of method annotations in this AnnotationDirectoryItem + */ + public int getMethodAnnotationCount() { + return methodAnnotationMethods.length; + } + /** * Iterates over the parameter annotations, calling delegate.processParameterAnnotations for each * @param delegate the delegate to call */ - public void iteratParameterAnnotations(ParameterAnnotationIteratorDelegate delegate) { + public void iterateParameterAnnotations(ParameterAnnotationIteratorDelegate delegate) { for (int i=0; i { void processParameterAnnotations(MethodIdItem method, AnnotationSetRefList parameterAnnotations); } + /** + * @return the number of parameter annotations in this AnnotationDirectoryItem + */ + public int getParameterAnnotationCount() { + return parameterAnnotationMethods.length; + } + /** * @return true if this AnnotationDirectoryItem is internable. It is only internable if it has * only class annotations, but no field, method or parameter annotations