Index: src/array.js |
diff --git a/src/array.js b/src/array.js |
index ef7aae4774f92764c788be57f4de4d3f62171e9f..5ef8f1141f80909f5879c89896fc386ee658a8d9 100644 |
--- a/src/array.js |
+++ b/src/array.js |
@@ -221,50 +221,6 @@ function SmartSlice(array, start_i, del_count, len, deleted_elements) { |
} |
-// This function implements the optimized splice implementation that can use |
-// special array operations to handle sparse arrays in a sensible fashion. |
-function SmartMove(array, start_i, del_count, len, num_additional_args) { |
- // Move data to new array. |
- var new_array = new InternalArray(len - del_count + num_additional_args); |
- var indices = %GetArrayKeys(array, len); |
- if (IS_NUMBER(indices)) { |
- var limit = indices; |
- for (var i = 0; i < start_i && i < limit; ++i) { |
- var current = array[i]; |
- if (!IS_UNDEFINED(current) || i in array) { |
- new_array[i] = current; |
- } |
- } |
- for (var i = start_i + del_count; i < limit; ++i) { |
- var current = array[i]; |
- if (!IS_UNDEFINED(current) || i in array) { |
- new_array[i - del_count + num_additional_args] = current; |
- } |
- } |
- } else { |
- var length = indices.length; |
- for (var k = 0; k < length; ++k) { |
- var key = indices[k]; |
- if (!IS_UNDEFINED(key)) { |
- if (key < start_i) { |
- var current = array[key]; |
- if (!IS_UNDEFINED(current) || key in array) { |
- new_array[key] = current; |
- } |
- } else if (key >= start_i + del_count) { |
- var current = array[key]; |
- if (!IS_UNDEFINED(current) || key in array) { |
- new_array[key - del_count + num_additional_args] = current; |
- } |
- } |
- } |
- } |
- } |
- // Move contents of new_array into this array |
- %MoveArrayContents(new_array, array); |
-} |
- |
- |
// This is part of the old simple-minded splice. We are using it either |
// 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. |
@@ -282,8 +238,9 @@ function SimpleSlice(array, start_i, del_count, len, deleted_elements) { |
} |
-function SimpleMove(array, start_i, del_count, len, num_additional_args) { |
- if (num_additional_args !== del_count) { |
+function SimpleMove(array, start_i, del_count, len, num_additional_args, |
+ force) { |
+ if (num_additional_args !== del_count || force) { |
rafaelw
2014/06/22 23:59:18
Note that |force| is required here because the spe
|
// Move the existing elements after the elements to be deleted |
// to the right position in the resulting array. |
if (num_additional_args > del_count) { |
@@ -586,11 +543,7 @@ function ArrayShift() { |
var first = array[0]; |
- if (IS_ARRAY(array)) { |
- SmartMove(array, 0, 1, len, 0); |
- } else { |
- SimpleMove(array, 0, 1, len, 0); |
- } |
+ SimpleMove(array, 0, 1, len, 0); |
array.length = len - 1; |
@@ -626,14 +579,7 @@ function ArrayUnshift(arg1) { // length == 1 |
var array = TO_OBJECT_INLINE(this); |
var len = TO_UINT32(array.length); |
var num_arguments = %_ArgumentsLength(); |
- var is_sealed = ObjectIsSealed(array); |
- |
- if (IS_ARRAY(array) && !is_sealed && len > 0) { |
- SmartMove(array, 0, 0, len, num_arguments); |
- } else { |
- SimpleMove(array, 0, 0, len, num_arguments); |
- } |
- |
+ SimpleMove(array, 0, 0, len, num_arguments, true); |
for (var i = 0; i < num_arguments; i++) { |
array[i] = %_Arguments(i); |
} |
@@ -783,25 +729,8 @@ function ArraySplice(start, delete_count) { |
["Array.prototype.splice"]); |
} |
- var use_simple_splice = true; |
- if (IS_ARRAY(array) && |
- num_elements_to_add !== del_count) { |
- // If we are only deleting/moving a few things near the end of the |
- // array then the simple version is going to be faster, because it |
- // doesn't touch most of the array. |
- var estimated_non_hole_elements = %EstimateNumberOfElements(array); |
- if (len > 20 && (estimated_non_hole_elements >> 2) < (len - start_i)) { |
- use_simple_splice = false; |
- } |
- } |
- |
- if (use_simple_splice) { |
- SimpleSlice(array, start_i, del_count, len, deleted_elements); |
- SimpleMove(array, start_i, del_count, len, num_elements_to_add); |
- } else { |
- SmartSlice(array, start_i, del_count, len, deleted_elements); |
- SmartMove(array, start_i, del_count, len, num_elements_to_add); |
- } |
+ SimpleSlice(array, start_i, del_count, len, deleted_elements); |
Toon Verwaest
2014/06/23 08:42:36
I guess now you can remove the "Simple" prefixes
|
+ SimpleMove(array, start_i, del_count, len, num_elements_to_add); |
// Insert the arguments into the resulting array in |
// place of the deleted elements. |