Index: src/runtime/runtime-typedarray.cc |
diff --git a/src/runtime/runtime-typedarray.cc b/src/runtime/runtime-typedarray.cc |
index f4643e0506337e84b37ce2214dc817559e2eb834..a057fc69bd40bf38efb561ed1480259d1779d680 100644 |
--- a/src/runtime/runtime-typedarray.cc |
+++ b/src/runtime/runtime-typedarray.cc |
@@ -336,27 +336,24 @@ RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) { |
namespace { |
-#define TYPED_ARRAY_SORT_COMPAREFN(Type, type, TYPE, ctype, size) \ |
- bool compare##Type(ctype x, ctype y) { \ |
- if (x < y) { \ |
- return true; \ |
- } else if (x > y) { \ |
- return false; \ |
- } else { \ |
- double _x = x, _y = y; \ |
- if (x == 0 && x == y) { \ |
- /* -0.0 is less than +0.0 */ \ |
- return std::signbit(_x) && !std::signbit(_y); \ |
- } else if (!std::isnan(_x) && std::isnan(_y)) { \ |
- /* number is less than NaN */ \ |
- return true; \ |
- } \ |
- } \ |
- return false; \ |
+template <typename T> |
+bool CompareNum(T x, T y) { |
+ if (x < y) { |
+ return true; |
+ } else if (x > y) { |
+ return false; |
+ } else if (!std::is_integral<T>::value) { |
+ double _x = x, _y = y; |
+ if (x == 0 && x == y) { |
+ /* -0.0 is less than +0.0 */ |
+ return std::signbit(_x) && !std::signbit(_y); |
+ } else if (!std::isnan(_x) && std::isnan(_y)) { |
+ /* number is less than NaN */ |
+ return true; |
+ } |
} |
- |
-TYPED_ARRAYS(TYPED_ARRAY_SORT_COMPAREFN) |
-#undef TYPED_ARRAY_SORT_COMPAREFN |
+ return false; |
+} |
} // namespace |
@@ -376,15 +373,19 @@ RUNTIME_FUNCTION(Runtime_TypedArraySortFast) { |
if (V8_UNLIKELY(array->WasNeutered())) return *array; |
size_t length = array->length_value(); |
- if (length == 0) return *array; |
+ if (length <= 1) return *array; |
switch (array->type()) { |
-#define TYPED_ARRAY_SORT(Type, type, TYPE, ctype, size) \ |
- case kExternal##Type##Array: { \ |
- ctype* backing_store = \ |
- static_cast<ctype*>(array->GetBuffer()->backing_store()); \ |
- std::sort(backing_store, backing_store + length, compare##Type); \ |
- break; \ |
+#define TYPED_ARRAY_SORT(Type, type, TYPE, ctype, size) \ |
+ case kExternal##Type##Array: { \ |
+ ctype* backing_store = \ |
+ static_cast<ctype*>(array->GetBuffer()->backing_store()); \ |
+ if (kExternal##Type##Array == kExternalFloat64Array || \ |
+ kExternal##Type##Array == kExternalFloat32Array) \ |
+ std::sort(backing_store, backing_store + length, CompareNum<ctype>); \ |
+ else \ |
+ std::sort(backing_store, backing_store + length); \ |
+ break; \ |
} |
TYPED_ARRAYS(TYPED_ARRAY_SORT) |