summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-03-16 19:25:20 -0700
committerJeff Brown <jeffbrown@google.com>2012-03-16 22:25:15 -0700
commitc9fd9263feedac32e4f5b1f13a3246347efdc25f (patch)
tree034a4002a842eae595f59f5d78d982e6316fb13d
parent61361f376b47d45966b1ca0d24d51622304c93c3 (diff)
downloadframeworks_base-c9fd9263feedac32e4f5b1f13a3246347efdc25f.zip
frameworks_base-c9fd9263feedac32e4f5b1f13a3246347efdc25f.tar.gz
frameworks_base-c9fd9263feedac32e4f5b1f13a3246347efdc25f.tar.bz2
Use quicksort to sort the string pool.
The current implementation of Vector::sort uses insertion sort on the assumption that the data is mostly sorted. It isn't. This change brings the total time spent sorting packages by config down to 500ms from about 93 seconds. Bug: 6186278 Change-Id: Iec8da11e09297acd6c73733d063b0fa9dacf69f7
-rw-r--r--tools/aapt/StringPool.cpp14
-rw-r--r--tools/aapt/StringPool.h2
2 files changed, 10 insertions, 6 deletions
diff --git a/tools/aapt/StringPool.cpp b/tools/aapt/StringPool.cpp
index 963ae59..b6295bd 100644
--- a/tools/aapt/StringPool.cpp
+++ b/tools/aapt/StringPool.cpp
@@ -213,11 +213,11 @@ status_t StringPool::addStyleSpan(size_t idx, const entry_style_span& span)
return NO_ERROR;
}
-int StringPool::config_sort(const size_t* lhs, const size_t* rhs, void* state)
+int StringPool::config_sort(void* state, const void* lhs, const void* rhs)
{
StringPool* pool = (StringPool*)state;
- const entry& lhe = pool->mEntries[pool->mEntryArray[*lhs]];
- const entry& rhe = pool->mEntries[pool->mEntryArray[*rhs]];
+ const entry& lhe = pool->mEntries[pool->mEntryArray[*static_cast<const size_t*>(lhs)]];
+ const entry& rhe = pool->mEntries[pool->mEntryArray[*static_cast<const size_t*>(rhs)]];
return lhe.compare(rhe);
}
@@ -232,13 +232,17 @@ void StringPool::sortByConfig()
// At that point it maps from the new position in the array to the
// original position the entry appeared.
Vector<size_t> newPosToOriginalPos;
- for (size_t i=0; i<mEntryArray.size(); i++) {
+ newPosToOriginalPos.setCapacity(N);
+ for (size_t i=0; i < N; i++) {
newPosToOriginalPos.add(i);
}
// Sort the array.
NOISY(printf("SORTING STRINGS BY CONFIGURATION...\n"));
- newPosToOriginalPos.sort(config_sort, this);
+ // Vector::sort uses insertion sort, which is very slow for this data set.
+ // Use quicksort instead because we don't need a stable sort here.
+ qsort_r(newPosToOriginalPos.editArray(), N, sizeof(size_t), this, config_sort);
+ //newPosToOriginalPos.sort(config_sort, this);
NOISY(printf("DONE SORTING STRINGS BY CONFIGURATION.\n"));
// Create the reverse mapping from the original position in the array
diff --git a/tools/aapt/StringPool.h b/tools/aapt/StringPool.h
index 060dc68..d501008 100644
--- a/tools/aapt/StringPool.h
+++ b/tools/aapt/StringPool.h
@@ -139,7 +139,7 @@ public:
const Vector<size_t>* offsetsForString(const String16& val) const;
private:
- static int config_sort(const size_t* lhs, const size_t* rhs, void* state);
+ static int config_sort(void* state, const void* lhs, const void* rhs);
const bool mUTF8;