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

Unified Diff: src/js/array.js

Issue 1785003004: Revert of Replace PushIfAbsent by a Stack object and move StringBuilderJoin to JS (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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/json.js » ('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 33c8120f34a9d32cd010bc6651effdb3ae001d8d..1468d57c6cae52f3f4c307609d1c58a9517382f5 100644
--- a/src/js/array.js
+++ b/src/js/array.js
@@ -74,6 +74,11 @@
}
+// Global list of arrays visited during toString, toLocaleString and
+// join invocations.
+var visited_arrays = new InternalArray();
+
+
// Gets a sorted array of array keys. Useful for operations on sparse
// arrays. Dupes have not been removed.
function GetSortedArrayKeys(array, indices) {
@@ -145,17 +150,6 @@
}
-function StringBuilderJoin(elements, length, separator) {
- length = MinSimple(elements.length, length);
- if (length == 0) return "";
- var result = elements[0];
- for (var i = 1; i < length; i++) {
- result = result + separator + elements[i];
- }
- return result;
-}
-
-
function UseSparseVariant(array, length, is_array, touched) {
// Only use the sparse variant on arrays that are likely to be sparse and the
// number of elements touched in the operation is relatively small compared to
@@ -173,36 +167,6 @@
(touched > estimated_elements * 4);
}
-function Stack() {
- this.length = 0;
- this.values = new InternalArray();
-}
-
-// Predeclare the instance variables on the prototype. Otherwise setting them in
-// the constructor will leak the instance through settings on Object.prototype.
-Stack.prototype.length = null;
-Stack.prototype.values = null;
-
-function StackPush(stack, value) {
- stack.values[stack.length++] = value;
-}
-
-function StackPop(stack) {
- stack.values[--stack.length] = null
-}
-
-function StackHas(stack, v) {
- var length = stack.length;
- var values = stack.values;
- for (var i = 0; i < length; i++) {
- if (values[i] === v) return true;
- }
- return false;
-}
-
-// Global list of arrays visited during toString, toLocaleString and
-// join invocations.
-var visited_arrays = new Stack();
function Join(array, length, separator, convert) {
if (length == 0) return '';
@@ -212,8 +176,7 @@
if (is_array) {
// If the array is cyclic, return the empty string for already
// visited arrays.
- if (StackHas(visited_arrays, array)) return '';
- StackPush(visited_arrays, array);
+ if (!%PushIfAbsent(visited_arrays, array)) return '';
}
// Attempt to convert the elements.
@@ -272,11 +235,11 @@
elements[i] = e;
}
}
- return StringBuilderJoin(elements, length, separator);
+ return %StringBuilderJoin(elements, length, separator);
} finally {
// Make sure to remove the last element of the visited array no
// matter what happens.
- if (is_array) StackPop(visited_arrays);
+ if (is_array) visited_arrays.length = visited_arrays.length - 1;
}
}
@@ -1996,10 +1959,6 @@
to.InnerArraySort = InnerArraySort;
to.InnerArrayToLocaleString = InnerArrayToLocaleString;
to.PackedArrayReverse = PackedArrayReverse;
- to.Stack = Stack;
- to.StackHas = StackHas;
- to.StackPush = StackPush;
- to.StackPop = StackPop;
});
%InstallToContext([
« no previous file with comments | « no previous file | src/js/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698