function SparseMove(array, start_i, del_count, len, num_additional_args) {
  // Bail out if no moving is necessary.
  if (num_additional_args === del_count) return;
  // Move data to new array.
  var new_array = new InternalArray(
      // Clamp array length to 2^32-1 to avoid early RangeError.
      MinSimple(len - del_count + num_additional_args, 0xffffffff));
  var big_indices;
  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 (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) {
          var new_key = key - del_count + num_additional_args;
          new_array[new_key] = current;
          if (new_key > 0xfffffffe) {
            big_indices = big_indices || new InternalArray();
            big_indices.push(new_key);
          }
        }
      }
    }
  }
  // Move contents of new_array into this array
  %MoveArrayContents(new_array, array);
  // Add any moved values that aren't elements anymore.
  if (!IS_UNDEFINED(big_indices)) {
    var length = big_indices.length;
    for (var i = 0; i < length; ++i) {
      var key = big_indices[i];
      array[key] = new_array[key];
    }
  }
}
function SparseMove(array, start_i, del_count, len, num_additional_args) {
  
  if (num_additional_args === del_count) return;
  
  var new_array = new InternalArray(
      
      MinSimple(len - del_count + num_additional_args, 0xffffffff));
  var big_indices;
  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 (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) {
          var new_key = key - del_count + num_additional_args;
          new_array[new_key] = current;
          if (new_key > 0xfffffffe) {
            big_indices = big_indices || new InternalArray();
            big_indices.push(new_key);
          }
        }
      }
    }
  }
  
  %MoveArrayContents(new_array, array);
  
  if (!IS_UNDEFINED(big_indices)) {
    var length = big_indices.length;
    for (var i = 0; i < length; ++i) {
      var key = big_indices[i];
      array[key] = new_array[key];
    }
  }
}
function SparseMove ( array , start_i , del_count , len , num_additional_args ) { // Bail out if no moving is necessary. if ( num_additional_args === del_count ) return ; // Move data to new array. var new_array = new InternalArray ( // Clamp array length to 2^32-1 to avoid early RangeError. MinSimple ( len - del_count + num_additional_args , 0xffffffff ) ) ; var big_indices ; 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 ( 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 ) { var new_key = key - del_count + num_additional_args ; new_array [ new_key ] = current ; if ( new_key > 0xfffffffe ) { big_indices = big_indices || new InternalArray ( ) ; big_indices . push ( new_key ) ; } } } } } // Move contents of new_array into this array % MoveArrayContents ( new_array , array ) ; // Add any moved values that aren't elements anymore. if ( ! IS_UNDEFINED ( big_indices ) ) { var length = big_indices . length ; for ( var i = 0 ; i < length ; ++ i ) { var key = big_indices [ i ] ; array [ key ] = new_array [ key ] ; } } }
This function implements the optimized splice implementation that can use special array operations to handle sparse arrays in a sensible fashion.
This function implements the optimized splice implementation that can use special array operations to handle sparse arrays in a sensible fashion .