mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
perf(streams): memory optimizations by avoiding large buffer allocation in a loop (#2748)
This commit is contained in:
parent
385511bc43
commit
c5323d365a
@ -494,14 +494,14 @@ export async function* iterateReader(
|
||||
},
|
||||
): AsyncIterableIterator<Uint8Array> {
|
||||
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
||||
const b = new Uint8Array(bufSize);
|
||||
while (true) {
|
||||
const b = new Uint8Array(bufSize);
|
||||
const result = await r.read(b);
|
||||
if (result === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
yield b.subarray(0, result);
|
||||
yield b.slice(0, result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -545,14 +545,14 @@ export function* iterateReaderSync(
|
||||
},
|
||||
): IterableIterator<Uint8Array> {
|
||||
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
||||
const b = new Uint8Array(bufSize);
|
||||
while (true) {
|
||||
const b = new Uint8Array(bufSize);
|
||||
const result = r.readSync(b);
|
||||
if (result === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
yield b.subarray(0, result);
|
||||
yield b.slice(0, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user