mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Simplify bufferClone.
This commit is contained in:
@@ -773,18 +773,6 @@
|
||||
Uint8Array = getNative(context, 'Uint8Array'),
|
||||
WeakMap = getNative(context, 'WeakMap');
|
||||
|
||||
/** Used to clone array buffers. */
|
||||
var Float64Array = (function() {
|
||||
// Safari 5 errors when using an array buffer to initialize a typed array
|
||||
// where the array buffer's `byteLength` is not a multiple of the typed
|
||||
// array's `BYTES_PER_ELEMENT`.
|
||||
try {
|
||||
var func = getNative(context, 'Float64Array'),
|
||||
result = new func(new ArrayBuffer(10), 0, 1) && func;
|
||||
} catch(e) {}
|
||||
return result || null;
|
||||
}());
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeCreate = getNative(Object, 'create'),
|
||||
nativeIsArray = getNative(Array, 'isArray'),
|
||||
@@ -806,9 +794,6 @@
|
||||
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
|
||||
HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
|
||||
|
||||
/** Used as the size, in bytes, of each `Float64Array` element. */
|
||||
var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
|
||||
|
||||
/**
|
||||
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
||||
* of an array-like value.
|
||||
@@ -3030,19 +3015,10 @@
|
||||
* @returns {ArrayBuffer} Returns the cloned array buffer.
|
||||
*/
|
||||
var bufferClone = !(ArrayBuffer && Uint8Array) ? constant(null) : function(buffer) {
|
||||
var byteLength = buffer.byteLength,
|
||||
floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0,
|
||||
offset = floatLength * FLOAT64_BYTES_PER_ELEMENT,
|
||||
result = new ArrayBuffer(byteLength);
|
||||
var result = new ArrayBuffer(buffer.byteLength),
|
||||
view = new Uint8Array(result);
|
||||
|
||||
if (floatLength) {
|
||||
var view = new Float64Array(result, 0, floatLength);
|
||||
view.set(new Float64Array(buffer, 0, floatLength));
|
||||
}
|
||||
if (byteLength != offset) {
|
||||
view = new Uint8Array(result, offset);
|
||||
view.set(new Uint8Array(buffer, offset));
|
||||
}
|
||||
view.set(new Uint8Array(buffer));
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user