Skip to content

Commit 5f3b32c

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Use qsort_r_compat() as a portable wrapper for qsort_r()."
2 parents fae7ab3 + fe75d62 commit 5f3b32c

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

tools/aapt/StringPool.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <utils/ByteOrder.h>
1111
#include <utils/SortedVector.h>
12+
#include <cutils/qsort_r_compat.h>
1213

1314
#if HAVE_PRINTF_ZD
1415
# define ZD "%zd"
@@ -213,11 +214,7 @@ status_t StringPool::addStyleSpan(size_t idx, const entry_style_span& span)
213214
return NO_ERROR;
214215
}
215216

216-
#ifdef __GLIBC__
217-
int StringPool::config_sort(const void* lhs, const void* rhs, void* state)
218-
#else
219217
int StringPool::config_sort(void* state, const void* lhs, const void* rhs)
220-
#endif
221218
{
222219
StringPool* pool = (StringPool*)state;
223220
const entry& lhe = pool->mEntries[pool->mEntryArray[*static_cast<const size_t*>(lhs)]];
@@ -245,13 +242,7 @@ void StringPool::sortByConfig()
245242
NOISY(printf("SORTING STRINGS BY CONFIGURATION...\n"));
246243
// Vector::sort uses insertion sort, which is very slow for this data set.
247244
// Use quicksort instead because we don't need a stable sort here.
248-
// For more fun, GLibC took qsort_r from BSD but then decided to swap the
249-
// order the last two parameters.
250-
#ifdef __GLIBC__
251-
qsort_r(newPosToOriginalPos.editArray(), N, sizeof(size_t), config_sort, this);
252-
#else
253-
qsort_r(newPosToOriginalPos.editArray(), N, sizeof(size_t), this, config_sort);
254-
#endif
245+
qsort_r_compat(newPosToOriginalPos.editArray(), N, sizeof(size_t), this, config_sort);
255246
//newPosToOriginalPos.sort(config_sort, this);
256247
NOISY(printf("DONE SORTING STRINGS BY CONFIGURATION.\n"));
257248

tools/aapt/StringPool.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ class StringPool
139139
const Vector<size_t>* offsetsForString(const String16& val) const;
140140

141141
private:
142-
#ifdef __GLIBC__
143-
static int config_sort(const void* lhs, const void* rhs, void* state);
144-
#else
145142
static int config_sort(void* state, const void* lhs, const void* rhs);
146-
#endif
147143

148144
const bool mUTF8;
149145

0 commit comments

Comments
 (0)