Add ol.array.safeExtend
This commit is contained in:
@@ -37,6 +37,25 @@ ol.array.binaryFindNearest = function(arr, target) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safe version of goog.array.extend that does not risk to overflow the stack
|
||||||
|
* even if `array2` contains a large number of elements.
|
||||||
|
*
|
||||||
|
* @param {Array.<T>} array1 Array 1.
|
||||||
|
* @param {Array.<T>} array2 Array 2.
|
||||||
|
* @template T
|
||||||
|
*/
|
||||||
|
ol.array.safeExtend = function(array1, array2) {
|
||||||
|
// goog.array.extend uses Array.prototype.push.apply, which can overflow the
|
||||||
|
// stack if array2 contains too many elements. Repeatedly calling push
|
||||||
|
// performs as well on modern browsers.
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = array2.length; i < ii; ++i) {
|
||||||
|
array1.push(array2[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array.<number>} arr Array.
|
* @param {Array.<number>} arr Array.
|
||||||
* @param {number} target Target.
|
* @param {number} target Target.
|
||||||
|
|||||||
Reference in New Issue
Block a user