Anonymous avatar Anonymous committed 3b79b5b Merge

Merge "Don't duplicate annotation set ref lists when merging."

Comments (0)

Files changed (2)

dx/src/com/android/dx/merge/DexMerger.java

     private void unionAnnotationSetsAndDirectories() {
         transformAnnotationSets(dexA, aIndexMap);
         transformAnnotationSets(dexB, bIndexMap);
+        transformAnnotationSetRefLists(dexA, aIndexMap);
+        transformAnnotationSetRefLists(dexB, bIndexMap);
         transformAnnotationDirectories(dexA, aIndexMap);
         transformAnnotationDirectories(dexB, bIndexMap);
         transformStaticValues(dexA, aIndexMap);
         }
     }
 
+    private void transformAnnotationSetRefLists(DexBuffer in, IndexMap indexMap) {
+        TableOfContents.Section section = in.getTableOfContents().annotationSetRefLists;
+        if (section.exists()) {
+            DexBuffer.Section setIn = in.open(section.off);
+            for (int i = 0; i < section.size; i++) {
+                transformAnnotationSetRefList(indexMap, setIn);
+            }
+        }
+    }
+
     private void transformAnnotationDirectories(DexBuffer in, IndexMap indexMap) {
         TableOfContents.Section section = in.getTableOfContents().annotationsDirectories;
         if (section.exists()) {
             DexBuffer.Section directoryIn = in.open(section.off);
             for (int i = 0; i < section.size; i++) {
-                transformAnnotationDirectory(in, directoryIn, indexMap);
+                transformAnnotationDirectory(directoryIn, indexMap);
             }
         }
     }
      * Transform all annotations on a class.
      */
     private void transformAnnotationDirectory(
-            DexBuffer in, DexBuffer.Section directoryIn, IndexMap indexMap) {
+            DexBuffer.Section directoryIn, IndexMap indexMap) {
         contentsOut.annotationsDirectories.size++;
         annotationsDirectoryOut.assertFourByteAligned();
         indexMap.putAnnotationDirectoryOffset(
         }
 
         for (int i = 0; i < parameterListSize; i++) {
-            contentsOut.annotationSetRefLists.size++;
-            annotationSetRefListOut.assertFourByteAligned();
-
             // method index
             annotationsDirectoryOut.writeInt(indexMap.adjustMethod(directoryIn.readInt()));
 
             // annotations offset
-            annotationsDirectoryOut.writeInt(annotationSetRefListOut.getPosition());
-            DexBuffer.Section refListIn = in.open(directoryIn.readInt());
-
-            // parameters
-            int parameterCount = refListIn.readInt();
-            annotationSetRefListOut.writeInt(parameterCount);
-            for (int p = 0; p < parameterCount; p++) {
-                annotationSetRefListOut.writeInt(indexMap.adjustAnnotationSet(refListIn.readInt()));
-            }
+            annotationsDirectoryOut.writeInt(
+                    indexMap.adjustAnnotationSetRefList(directoryIn.readInt()));
         }
     }
 
         }
     }
 
+    /**
+     * Transform all annotation set ref lists.
+     */
+    private void transformAnnotationSetRefList(IndexMap indexMap, DexBuffer.Section refListIn) {
+        contentsOut.annotationSetRefLists.size++;
+        annotationSetRefListOut.assertFourByteAligned();
+        indexMap.putAnnotationSetRefListOffset(
+                refListIn.getPosition(), annotationSetRefListOut.getPosition());
+
+        int parameterCount = refListIn.readInt();
+        annotationSetRefListOut.writeInt(parameterCount);
+        for (int p = 0; p < parameterCount; p++) {
+            annotationSetRefListOut.writeInt(indexMap.adjustAnnotationSet(refListIn.readInt()));
+        }
+    }
+
     private void transformClassData(DexBuffer in, ClassData classData, IndexMap indexMap) {
         contentsOut.classDatas.size++;
 

dx/src/com/android/dx/merge/IndexMap.java

     private final HashMap<Integer, Integer> typeListOffsets;
     private final HashMap<Integer, Integer> annotationOffsets;
     private final HashMap<Integer, Integer> annotationSetOffsets;
+    private final HashMap<Integer, Integer> annotationSetRefListOffsets;
     private final HashMap<Integer, Integer> annotationDirectoryOffsets;
     private final HashMap<Integer, Integer> staticValuesOffsets;
 
         this.typeListOffsets = new HashMap<Integer, Integer>();
         this.annotationOffsets = new HashMap<Integer, Integer>();
         this.annotationSetOffsets = new HashMap<Integer, Integer>();
+        this.annotationSetRefListOffsets = new HashMap<Integer, Integer>();
         this.annotationDirectoryOffsets = new HashMap<Integer, Integer>();
         this.staticValuesOffsets = new HashMap<Integer, Integer>();
 
         annotationSetOffsets.put(oldOffset, newOffset);
     }
 
+    public void putAnnotationSetRefListOffset(int oldOffset, int newOffset) {
+        if (oldOffset <= 0 || newOffset <= 0) {
+            throw new IllegalArgumentException();
+        }
+        annotationSetRefListOffsets.put(oldOffset, newOffset);
+    }
+
     public void putAnnotationDirectoryOffset(int oldOffset, int newOffset) {
         if (oldOffset <= 0 || newOffset <= 0) {
             throw new IllegalArgumentException();
         return annotationSetOffsets.get(annotationSetOffset);
     }
 
+    public int adjustAnnotationSetRefList(int annotationSetRefListOffset) {
+        return annotationSetRefListOffsets.get(annotationSetRefListOffset);
+    }
+
     public int adjustAnnotationDirectory(int annotationDirectoryOffset) {
         return annotationDirectoryOffsets.get(annotationDirectoryOffset);
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.