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

Unified Diff: src/array.js

Issue 1238593003: Array.prototype.reverse should call [[HasProperty]] on elements before [[Get]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add packed implementation Created 5 years, 5 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/harmony-typedarray.js » ('j') | test/mjsunit/es6/array-reverse-order.js » ('J')
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 7baabf83610c3c333eb13b9a5463c652ccaa3839..394ebd080758e8823ac4bd29ec268c1fdd0dd8a5 100644
--- a/src/array.js
+++ b/src/array.js
@@ -567,10 +567,10 @@ function SparseReverse(array, len) {
high = len - i - 1;
}
- var current_i = array[low];
- if (!IS_UNDEFINED(current_i) || low in array) {
adamk 2015/07/16 22:08:13 As discussed offline, I don't think SparseReverse
Dan Ehrenberg 2015/07/16 22:16:49 Done.
- var current_j = array[high];
- if (!IS_UNDEFINED(current_j) || high in array) {
+ if (low in array) {
+ var current_i = array[low];
+ if (high in array) {
+ var current_j = array[high];
array[low] = current_j;
array[high] = current_i;
} else {
@@ -578,8 +578,8 @@ function SparseReverse(array, len) {
delete array[low];
}
} else {
- var current_j = array[high];
- if (!IS_UNDEFINED(current_j) || high in array) {
+ if (high in array) {
+ var current_j = array[high];
array[low] = current_j;
delete array[high];
}
@@ -587,14 +587,25 @@ function SparseReverse(array, len) {
}
}
+function PackedArrayReverse(array, len) {
+ var j = len - 1;
+ for (var i = 0; i < j; i++, j--) {
+ var current_i = array[i];
+ var current_j = array[j];
+ array[i] = current_j;
+ array[j] = current_i;
+ }
+ return array;
+}
+
function InnerArrayReverse(array, len) {
var j = len - 1;
for (var i = 0; i < j; i++, j--) {
- var current_i = array[i];
- if (!IS_UNDEFINED(current_i) || i in array) {
- var current_j = array[j];
- if (!IS_UNDEFINED(current_j) || j in array) {
+ if (i in array) {
+ var current_i = array[i];
+ if (j in array) {
+ var current_j = array[j];
array[i] = current_j;
array[j] = current_i;
} else {
@@ -602,8 +613,8 @@ function InnerArrayReverse(array, len) {
delete array[i];
}
} else {
- var current_j = array[j];
- if (!IS_UNDEFINED(current_j) || j in array) {
+ if (j in array) {
+ var current_j = array[j];
array[i] = current_j;
delete array[j];
}
@@ -623,9 +634,11 @@ function ArrayReverse() {
%NormalizeElements(array);
SparseReverse(array, len);
return array;
+ } else if (%_HasFastPackedElements(array)) {
adamk 2015/07/16 22:08:13 This needs an IS_ARRAY check (you can cache this a
Toon Verwaest 2015/07/16 22:15:32 Do we have objects with packed elements that are n
Dan Ehrenberg 2015/07/16 22:16:49 Done.
+ return PackedArrayReverse(array, len);
+ } else {
+ return InnerArrayReverse(array, len);
adamk 2015/07/16 22:08:13 how about "GenericArrayReverse" as the name for th
Dan Ehrenberg 2015/07/16 22:16:49 Done.
}
-
- return InnerArrayReverse(array, len);
}
@@ -1688,10 +1701,10 @@ utils.Export(function(to) {
to.InnerArrayMap = InnerArrayMap;
to.InnerArrayReduce = InnerArrayReduce;
to.InnerArrayReduceRight = InnerArrayReduceRight;
- to.InnerArrayReverse = InnerArrayReverse;
to.InnerArraySome = InnerArraySome;
to.InnerArraySort = InnerArraySort;
to.InnerArrayToLocaleString = InnerArrayToLocaleString;
+ to.PackedArrayReverse = PackedArrayReverse;
});
$arrayConcat = ArrayConcatJS;
« no previous file with comments | « no previous file | src/harmony-typedarray.js » ('j') | test/mjsunit/es6/array-reverse-order.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698