From: Jeff Brown Date: Sat, 17 Mar 2012 02:25:20 +0000 (-0700) Subject: Use quicksort to sort the string pool. X-Git-Url: https://git.saurik.com/android/aapt.git/commitdiff_plain/d7ed9a895836fcb5ba7723dfb42d1dab73bc1cb0 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 --- diff --git a/StringPool.cpp b/StringPool.cpp index 963ae59..b6295bd 100644 --- a/StringPool.cpp +++ b/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(lhs)]]; + const entry& rhe = pool->mEntries[pool->mEntryArray[*static_cast(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 newPosToOriginalPos; - for (size_t i=0; i* 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;