mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
Revert "perf: improve Buffer.from(buf) by 29x" (#24351)
https://github.com/denoland/deno/pull/24341#discussion_r1655247367 Reverts denoland/deno#24341
This commit is contained in:
parent
2549e5154c
commit
77ba0019e7
1 changed files with 0 additions and 11 deletions
|
@ -229,22 +229,11 @@ function fromArrayLike(array) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fromUint8Array(u8) {
|
|
||||||
const buf = new Uint8Array(u8.buffer, u8.byteOffset, u8.byteLength);
|
|
||||||
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
||||||
return buf.slice();
|
|
||||||
}
|
|
||||||
|
|
||||||
function fromObject(obj) {
|
function fromObject(obj) {
|
||||||
if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
|
if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
|
||||||
if (typeof obj.length !== "number") {
|
if (typeof obj.length !== "number") {
|
||||||
return createBuffer(0);
|
return createBuffer(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj instanceof Uint8Array) {
|
|
||||||
return fromUint8Array(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fromArrayLike(obj);
|
return fromArrayLike(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue