Commit 82dfe3e0 authored by benjamin@webkit.org's avatar benjamin@webkit.org
Browse files

Use QuickSort when sorting primitive values by string representation

https://bugs.webkit.org/show_bug.cgi?id=83312

Patch by Benjamin Poulain <bpoulain@apple.com> on 2012-04-05
Reviewed by Gavin Barraclough.

When the value we are sorting are all primitive values, we do not need to
ensure a stable sort as two values with equal string representation are
indistinguishable from JavaScript.

This gives about 16% performance increase when sorting primitive values.

* runtime/JSArray.cpp:
(JSC::JSArray::sort):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@113391 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e876f360
2012-04-05 Benjamin Poulain <bpoulain@apple.com>
Use QuickSort when sorting primitive values by string representation
https://bugs.webkit.org/show_bug.cgi?id=83312
Reviewed by Gavin Barraclough.
When the value we are sorting are all primitive values, we do not need to
ensure a stable sort as two values with equal string representation are
indistinguishable from JavaScript.
This gives about 16% performance increase when sorting primitive values.
* runtime/JSArray.cpp:
(JSC::JSArray::sort):
2012-04-05 Oliver Hunt <oliver@apple.com>
 
SIGILL in JavaScriptCore on a Geode processor
......@@ -1475,10 +1475,12 @@ void JSArray::sort(ExecState* exec)
Heap::heap(this)->pushTempSortVector(&values);
bool isSortingPrimitiveValues = true;
for (size_t i = 0; i < lengthNotIncludingUndefined; i++) {
JSValue value = m_storage->m_vector[i].get();
ASSERT(!value.isUndefined());
values[i].first = value;
isSortingPrimitiveValues = isSortingPrimitiveValues && value.isPrimitive();
}
// FIXME: The following loop continues to call toString on subsequent values even after
......@@ -1496,7 +1498,10 @@ void JSArray::sort(ExecState* exec)
// than O(N log N).
#if HAVE(MERGESORT)
mergesort(values.begin(), values.size(), sizeof(ValueStringPair), compareByStringPairForQSort);
if (isSortingPrimitiveValues)
qsort(values.begin(), values.size(), sizeof(ValueStringPair), compareByStringPairForQSort);
else
mergesort(values.begin(), values.size(), sizeof(ValueStringPair), compareByStringPairForQSort);
#else
// FIXME: The qsort library function is likely to not be a stable sort.
// ECMAScript-262 does not specify a stable sort, but in practice, browsers perform a stable sort.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment