Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Unified Diff: src/array.js

Issue 1623004: Faster invocation of custom comparator function. (Closed)
Patch Set: Next round Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/arm/virtual-frame-arm.cc ('k') | src/codegen.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/array.js
diff --git a/src/array.js b/src/array.js
index 4a2be989a36ff401cd5fda8efc934e2f62204eb5..c1ba3c399d904533a1613b86f07b90d76a906678 100644
--- a/src/array.js
+++ b/src/array.js
@@ -644,6 +644,8 @@ function ArraySort(comparefn) {
// In-place QuickSort algorithm.
// For short (length <= 22) arrays, insertion sort is used for efficiency.
+ var global_receiver;
+
function InsertionSortWithFunc(a, from, to) {
for (var i = from + 1; i < to; i++) {
var element = a[i];
@@ -654,8 +656,7 @@ function ArraySort(comparefn) {
// The search interval is a[min..max[
while (min < max) {
var mid = min + ((max - min) >> 1);
- var order = (a[mid] === element) ?
- 0 : comparefn.call(null, a[mid], element);
+ var order = %_CallFunction(global_receiver, a[mid], element, comparefn);
if (order == 0) {
min = max = mid;
break;
@@ -692,8 +693,7 @@ function ArraySort(comparefn) {
// From i to high_start are elements that haven't been compared yet.
for (var i = from + 1; i < high_start; ) {
var element = a[i];
- var order = (element === pivot) ?
- 0 : comparefn.call(null, element, pivot);
+ var order = %_CallFunction(global_receiver, element, pivot, comparefn);
if (order < 0) {
a[i] = a[low_end];
a[low_end] = element;
@@ -938,6 +938,7 @@ function ArraySort(comparefn) {
}
if(IS_FUNCTION(comparefn)) {
+ global_receiver = %GetGlobalReceiver();
QuickSortWithFunc(this, 0, num_non_undefined);
} else {
QuickSort(this, 0, num_non_undefined);
« no previous file with comments | « src/arm/virtual-frame-arm.cc ('k') | src/codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698