Use Buffer.allocUnsafe when available.

This commit is contained in:
John-David Dalton
2016-09-23 16:48:36 -07:00
parent a3c215919d
commit 549def0e48

View File

@@ -1470,6 +1470,7 @@
var Buffer = moduleExports ? context.Buffer : undefined, var Buffer = moduleExports ? context.Buffer : undefined,
Symbol = context.Symbol, Symbol = context.Symbol,
Uint8Array = context.Uint8Array, Uint8Array = context.Uint8Array,
allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
defineProperty = Object.defineProperty, defineProperty = Object.defineProperty,
getPrototype = overArg(Object.getPrototypeOf, Object), getPrototype = overArg(Object.getPrototypeOf, Object),
iteratorSymbol = Symbol ? Symbol.iterator : undefined, iteratorSymbol = Symbol ? Symbol.iterator : undefined,
@@ -4424,7 +4425,9 @@
if (isDeep) { if (isDeep) {
return buffer.slice(); return buffer.slice();
} }
var result = new buffer.constructor(buffer.length); var length = buffer.length,
result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
buffer.copy(result); buffer.copy(result);
return result; return result;
} }