From 7a7c29caf280ea038fb29377a75586bc5b527857 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Mon, 19 Mar 2012 14:08:58 -0700 Subject: [PATCH 1/1] Use qsort_r_compat() as a portable wrapper for qsort_r(). Change-Id: Ie79f81625947f4e95122047605d994c86e872e74 --- StringPool.cpp | 13 ++----------- StringPool.h | 4 ---- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/StringPool.cpp b/StringPool.cpp index a9941b4..839eda5 100644 --- a/StringPool.cpp +++ b/StringPool.cpp @@ -9,6 +9,7 @@ #include #include +#include #if HAVE_PRINTF_ZD # define ZD "%zd" @@ -213,11 +214,7 @@ status_t StringPool::addStyleSpan(size_t idx, const entry_style_span& span) return NO_ERROR; } -#ifdef __GLIBC__ -int StringPool::config_sort(const void* lhs, const void* rhs, void* state) -#else int StringPool::config_sort(void* state, const void* lhs, const void* rhs) -#endif { StringPool* pool = (StringPool*)state; const entry& lhe = pool->mEntries[pool->mEntryArray[*static_cast(lhs)]]; @@ -245,13 +242,7 @@ void StringPool::sortByConfig() NOISY(printf("SORTING STRINGS BY CONFIGURATION...\n")); // 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. - // For more fun, GLibC took qsort_r from BSD but then decided to swap the - // order the last two parameters. -#ifdef __GLIBC__ - qsort_r(newPosToOriginalPos.editArray(), N, sizeof(size_t), config_sort, this); -#else - qsort_r(newPosToOriginalPos.editArray(), N, sizeof(size_t), this, config_sort); -#endif + qsort_r_compat(newPosToOriginalPos.editArray(), N, sizeof(size_t), this, config_sort); //newPosToOriginalPos.sort(config_sort, this); NOISY(printf("DONE SORTING STRINGS BY CONFIGURATION.\n")); diff --git a/StringPool.h b/StringPool.h index 64acfd8..d501008 100644 --- a/StringPool.h +++ b/StringPool.h @@ -139,11 +139,7 @@ public: const Vector* offsetsForString(const String16& val) const; private: -#ifdef __GLIBC__ - static int config_sort(const void* lhs, const void* rhs, void* state); -#else static int config_sort(void* state, const void* lhs, const void* rhs); -#endif const bool mUTF8; -- 2.45.2