llvm.org GIT mirror llvm / 545fc87
define array_pod_sort in terms of operator< instead of my brain damaged approximation. This should fix it on big endian platforms and on 64-bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60352 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
1 changed file(s) with 9 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
221221 }
222222
223223 /// array_pod_sort_comparator - This is helper function for array_pod_sort,
224 /// which does a memcmp of a specific size.
225 template
224 /// which just uses operator< on T.
225 template
226226 static inline int array_pod_sort_comparator(const void *P1, const void *P2) {
227 if (Size == sizeof(char))
228 return *(const char*)P1 - *(const char*)P2;
229 if (Size == sizeof(int))
230 return *(const int*)P1 - *(const int*)P2;
231 if (Size == sizeof(long long))
232 return *(const long long*)P1 - *(const long long*)P2;
233 if (Size == sizeof(intptr_t))
234 return *(intptr_t*)P1 - *(intptr_t*)P2;
235 return memcmp(P1, P2, Size);
227 if (*reinterpret_cast(P1) < *reinterpret_cast(P2))
228 return -1;
229 if (*reinterpret_cast(P2) < *reinterpret_cast(P1))
230 return 1;
231 return 0;
236232 }
237233
238234 /// array_pod_sort - This sorts an array with the specified start and end
244240 /// possible.
245241 ///
246242 /// This function assumes that you have simple POD-like types that can be
247 /// compared with memcmp and can be moved with memcpy. If this isn't true, you
248 /// should use std::sort.
243 /// compared with operator< and can be moved with memcpy. If this isn't true,
244 /// you should use std::sort.
249245 ///
250246 /// NOTE: If qsort_r were portable, we could allow a custom comparator and
251247 /// default to std::less.