@@ -74,6 +74,11 @@ function DefineIndexedProperty(array, i, value) {
7474}
7575
7676
77+ // Global list of arrays visited during toString, toLocaleString and
78+ // join invocations.
79+ var visited_arrays = new InternalArray ( ) ;
80+
81+
7782// Gets a sorted array of array keys. Useful for operations on sparse
7883// arrays. Dupes have not been removed.
7984function GetSortedArrayKeys ( array , indices ) {
@@ -145,17 +150,6 @@ function SparseJoin(array, len, convert) {
145150}
146151
147152
148- function StringBuilderJoin ( elements , length , separator ) {
149- length = MinSimple ( elements . length , length ) ;
150- if ( length == 0 ) return "" ;
151- var result = elements [ 0 ] ;
152- for ( var i = 1 ; i < length ; i ++ ) {
153- result = result + separator + elements [ i ] ;
154- }
155- return result ;
156- }
157-
158-
159153function UseSparseVariant ( array , length , is_array , touched ) {
160154 // Only use the sparse variant on arrays that are likely to be sparse and the
161155 // number of elements touched in the operation is relatively small compared to
@@ -173,36 +167,6 @@ function UseSparseVariant(array, length, is_array, touched) {
173167 ( touched > estimated_elements * 4 ) ;
174168}
175169
176- function Stack ( ) {
177- this . length = 0 ;
178- this . values = new InternalArray ( ) ;
179- }
180-
181- // Predeclare the instance variables on the prototype. Otherwise setting them in
182- // the constructor will leak the instance through settings on Object.prototype.
183- Stack . prototype . length = null ;
184- Stack . prototype . values = null ;
185-
186- function StackPush ( stack , value ) {
187- stack . values [ stack . length ++ ] = value ;
188- }
189-
190- function StackPop ( stack ) {
191- stack . values [ -- stack . length ] = null
192- }
193-
194- function StackHas ( stack , v ) {
195- var length = stack . length ;
196- var values = stack . values ;
197- for ( var i = 0 ; i < length ; i ++ ) {
198- if ( values [ i ] === v ) return true ;
199- }
200- return false ;
201- }
202-
203- // Global list of arrays visited during toString, toLocaleString and
204- // join invocations.
205- var visited_arrays = new Stack ( ) ;
206170
207171function Join ( array , length , separator , convert ) {
208172 if ( length == 0 ) return '' ;
@@ -212,8 +176,7 @@ function Join(array, length, separator, convert) {
212176 if ( is_array ) {
213177 // If the array is cyclic, return the empty string for already
214178 // visited arrays.
215- if ( StackHas ( visited_arrays , array ) ) return '' ;
216- StackPush ( visited_arrays , array ) ;
179+ if ( ! % PushIfAbsent ( visited_arrays , array ) ) return '' ;
217180 }
218181
219182 // Attempt to convert the elements.
@@ -272,11 +235,11 @@ function Join(array, length, separator, convert) {
272235 elements [ i ] = e ;
273236 }
274237 }
275- return StringBuilderJoin ( elements , length , separator ) ;
238+ return % StringBuilderJoin ( elements , length , separator ) ;
276239 } finally {
277240 // Make sure to remove the last element of the visited array no
278241 // matter what happens.
279- if ( is_array ) StackPop ( visited_arrays ) ;
242+ if ( is_array ) visited_arrays . length = visited_arrays . length - 1 ;
280243 }
281244}
282245
@@ -1996,10 +1959,6 @@ utils.Export(function(to) {
19961959 to . InnerArraySort = InnerArraySort ;
19971960 to . InnerArrayToLocaleString = InnerArrayToLocaleString ;
19981961 to . PackedArrayReverse = PackedArrayReverse ;
1999- to . Stack = Stack ;
2000- to . StackHas = StackHas ;
2001- to . StackPush = StackPush ;
2002- to . StackPop = StackPop ;
20031962} ) ;
20041963
20051964% InstallToContext ( [
0 commit comments