OSDN Git Service

aapt: Speed up the style pruning
authorChristopher R. Palmer <crpalmer@gmail.com>
Mon, 4 Jan 2016 10:18:31 +0000 (05:18 -0500)
committerSteve Kondik <steve@cyngn.com>
Sun, 4 Sep 2016 09:39:08 +0000 (02:39 -0700)
Prior to this commit it removed each style one by one which
causes the vector to repeatedly be shrunk and reallocated and
copied (aka either quadratic or NlogN in the number of items
removed).

This commit simply makes it remove them all at once to make it
linear instead.

Change-Id: I541d151675ab19f37d9de1e7a323104d0d3b3c63

tools/aapt/StringPool.cpp

index 9908c44..e449896 100644 (file)
@@ -349,14 +349,18 @@ void StringPool::sortByConfig()
 
     // Now trim any entries at the end of the new style array that are
     // not needed.
-    for (ssize_t i=newEntryStyleArray.size()-1; i>=0; i--) {
+    ssize_t i;
+    for (i=newEntryStyleArray.size()-1; i>=0; i--) {
         const entry_style& style = newEntryStyleArray[i];
         if (style.spans.size() > 0) {
             // That's it.
             break;
         }
-        // This one is not needed; remove.
-        newEntryStyleArray.removeAt(i);
+    }
+
+    ssize_t nToRemove=newEntryStyleArray.size()-(i+1);
+    if (nToRemove) {
+        newEntryStyleArray.removeItemsAt(i+1, nToRemove);
     }
 
     // All done, install the new data structures and upate mValues with