mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Perf: make readline interface creation faster
This commit is contained in:
parent
e5d511d105
commit
986cfc8ff4
@ -11,9 +11,14 @@ const decoder = new TextDecoder('utf-8');
|
|||||||
async function *createTextLineAsyncIterableFromStreamSource(stream: ReadableStream<Uint8Array>): AsyncIterable<string> {
|
async function *createTextLineAsyncIterableFromStreamSource(stream: ReadableStream<Uint8Array>): AsyncIterable<string> {
|
||||||
let buf = '';
|
let buf = '';
|
||||||
|
|
||||||
// @ts-expect-error -- ReadableStream<Uint8Array> should be AsyncIterable<Uint8Array>
|
const reader = stream.getReader();
|
||||||
for await (const chunk of stream) {
|
|
||||||
const chunkStr = decoder.decode(chunk).replaceAll('\r\n', '\n');
|
while (true) {
|
||||||
|
const res = await reader.read();
|
||||||
|
if (res.done) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const chunkStr = decoder.decode(res.value).replaceAll('\r\n', '\n');
|
||||||
for (let i = 0, len = chunkStr.length; i < len; i++) {
|
for (let i = 0, len = chunkStr.length; i < len; i++) {
|
||||||
const char = chunkStr[i];
|
const char = chunkStr[i];
|
||||||
if (char === '\n') {
|
if (char === '\n') {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user