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

Unified Diff: src/js/array.js

Issue 2013873002: [array] speed up array.forEach and friends by directly using in-operator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | src/js/macros.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/array.js
diff --git a/src/js/array.js b/src/js/array.js
index 3e8af8664edbb0e14f491679e1ad6111ae3abef9..2458fa398e20f58f24ca1c18bfb3e923b0e43fad 100644
--- a/src/js/array.js
+++ b/src/js/array.js
@@ -328,10 +328,9 @@ function SparseMove(array, start_i, del_count, len, num_additional_args) {
// because the receiver is not an array (so we have no choice) or because we
// know we are not deleting or moving a lot of elements.
function SimpleSlice(array, start_i, del_count, len, deleted_elements) {
- var is_array = IS_ARRAY(array);
for (var i = 0; i < del_count; i++) {
var index = start_i + i;
- if (HAS_INDEX(array, index, is_array)) {
+ if (HAS_INDEX(array, index)) {
var current = array[index];
%CreateDataProperty(deleted_elements, i, current);
}
@@ -340,7 +339,6 @@ function SimpleSlice(array, start_i, del_count, len, deleted_elements) {
function SimpleMove(array, start_i, del_count, len, num_additional_args) {
- var is_array = IS_ARRAY(array);
if (num_additional_args !== del_count) {
// Move the existing elements after the elements to be deleted
// to the right position in the resulting array.
@@ -348,7 +346,7 @@ function SimpleMove(array, start_i, del_count, len, num_additional_args) {
for (var i = len - del_count; i > start_i; i--) {
var from_index = i + del_count - 1;
var to_index = i + num_additional_args - 1;
- if (HAS_INDEX(array, from_index, is_array)) {
+ if (HAS_INDEX(array, from_index)) {
array[to_index] = array[from_index];
} else {
delete array[to_index];
@@ -358,7 +356,7 @@ function SimpleMove(array, start_i, del_count, len, num_additional_args) {
for (var i = start_i; i < len - del_count; i++) {
var from_index = i + del_count;
var to_index = i + num_additional_args;
- if (HAS_INDEX(array, from_index, is_array)) {
+ if (HAS_INDEX(array, from_index)) {
array[to_index] = array[from_index];
} else {
delete array[to_index];
@@ -1055,9 +1053,8 @@ function ArraySort(comparefn) {
// or delete elements from the array.
function InnerArrayFilter(f, receiver, array, length, result) {
var result_length = 0;
- var is_array = IS_ARRAY(array);
for (var i = 0; i < length; i++) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
var element = array[i];
if (%_Call(f, receiver, element, i, array)) {
%CreateDataProperty(result, result_length, element);
@@ -1086,17 +1083,16 @@ function ArrayFilter(f, receiver) {
function InnerArrayForEach(f, receiver, array, length) {
if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
- var is_array = IS_ARRAY(array);
if (IS_UNDEFINED(receiver)) {
for (var i = 0; i < length; i++) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
var element = array[i];
f(element, i, array);
}
}
} else {
for (var i = 0; i < length; i++) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
var element = array[i];
%_Call(f, receiver, element, i, array);
}
@@ -1119,9 +1115,8 @@ function ArrayForEach(f, receiver) {
function InnerArraySome(f, receiver, array, length) {
if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
- var is_array = IS_ARRAY(array);
for (var i = 0; i < length; i++) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
var element = array[i];
if (%_Call(f, receiver, element, i, array)) return true;
}
@@ -1146,9 +1141,8 @@ function ArraySome(f, receiver) {
function InnerArrayEvery(f, receiver, array, length) {
if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
- var is_array = IS_ARRAY(array);
for (var i = 0; i < length; i++) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
var element = array[i];
if (!%_Call(f, receiver, element, i, array)) return false;
}
@@ -1176,9 +1170,8 @@ function ArrayMap(f, receiver) {
var length = TO_LENGTH(array.length);
if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
var result = ArraySpeciesCreate(array, length);
- var is_array = IS_ARRAY(array);
for (var i = 0; i < length; i++) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
var element = array[i];
%CreateDataProperty(result, i, %_Call(f, receiver, element, i, array));
}
@@ -1317,11 +1310,10 @@ function InnerArrayReduce(callback, current, array, length, argumentsLength) {
throw MakeTypeError(kCalledNonCallable, callback);
}
- var is_array = IS_ARRAY(array);
var i = 0;
find_initial: if (argumentsLength < 2) {
for (; i < length; i++) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
current = array[i++];
break find_initial;
}
@@ -1330,7 +1322,7 @@ function InnerArrayReduce(callback, current, array, length, argumentsLength) {
}
for (; i < length; i++) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
var element = array[i];
current = callback(current, element, i, array);
}
@@ -1357,11 +1349,10 @@ function InnerArrayReduceRight(callback, current, array, length,
throw MakeTypeError(kCalledNonCallable, callback);
}
- var is_array = IS_ARRAY(array);
var i = length - 1;
find_initial: if (argumentsLength < 2) {
for (; i >= 0; i--) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
current = array[i--];
break find_initial;
}
@@ -1370,7 +1361,7 @@ function InnerArrayReduceRight(callback, current, array, length,
}
for (; i >= 0; i--) {
- if (HAS_INDEX(array, i, is_array)) {
+ if (HAS_INDEX(array, i)) {
var element = array[i];
current = callback(current, element, i, array);
}
« no previous file with comments | « no previous file | src/js/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698