mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
refactor(streams): prepare for noUncheckedIndexedAccess
(#4377)
This commit is contained in:
parent
58cb4ba9f3
commit
271a100e8f
@ -20,7 +20,7 @@ export function createLPS(pat: Uint8Array): Uint8Array {
|
|||||||
lps[i] = 0;
|
lps[i] = 0;
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
prefixEnd = lps[prefixEnd - 1];
|
prefixEnd = lps[prefixEnd - 1]!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lps;
|
return lps;
|
||||||
|
@ -116,7 +116,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
|
|||||||
// they are (with concatenation).
|
// they are (with concatenation).
|
||||||
if (bufs.length === 1) {
|
if (bufs.length === 1) {
|
||||||
// Concat not needed when a single buffer is passed.
|
// Concat not needed when a single buffer is passed.
|
||||||
controller.enqueue(bufs[0]);
|
controller.enqueue(bufs[0]!);
|
||||||
} else {
|
} else {
|
||||||
controller.enqueue(concat(bufs));
|
controller.enqueue(concat(bufs));
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
|
|||||||
} else if (delimitedChunkEnd < 0 && bufs.length > 0) {
|
} else if (delimitedChunkEnd < 0 && bufs.length > 0) {
|
||||||
// Our chunk started by finishing a partial delimiter match.
|
// Our chunk started by finishing a partial delimiter match.
|
||||||
const lastIndex = bufs.length - 1;
|
const lastIndex = bufs.length - 1;
|
||||||
const last = bufs[lastIndex];
|
const last = bufs[lastIndex]!;
|
||||||
const lastSliceIndex = last.byteLength + delimitedChunkEnd;
|
const lastSliceIndex = last.byteLength + delimitedChunkEnd;
|
||||||
const lastSliced = last.subarray(0, lastSliceIndex);
|
const lastSliced = last.subarray(0, lastSliceIndex);
|
||||||
if (lastIndex === 0) {
|
if (lastIndex === 0) {
|
||||||
@ -173,7 +173,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
|
|||||||
// but now got a new 'A', then we'll drop down to having matched
|
// but now got a new 'A', then we'll drop down to having matched
|
||||||
// just 'A'. The while loop will turn around again and we'll rematch
|
// just 'A'. The while loop will turn around again and we'll rematch
|
||||||
// to 'AA' and proceed onwards to try and match on 'B' again.
|
// to 'AA' and proceed onwards to try and match on 'B' again.
|
||||||
matchIndex = lps[matchIndex - 1];
|
matchIndex = lps[matchIndex - 1]!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Save match index.
|
// Save match index.
|
||||||
@ -231,7 +231,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
|
|||||||
// they are (with concatenation).
|
// they are (with concatenation).
|
||||||
if (bufs.length === 1) {
|
if (bufs.length === 1) {
|
||||||
// Concat not needed when a single buffer is passed.
|
// Concat not needed when a single buffer is passed.
|
||||||
controller.enqueue(bufs[0]);
|
controller.enqueue(bufs[0]!);
|
||||||
} else {
|
} else {
|
||||||
controller.enqueue(concat(bufs));
|
controller.enqueue(concat(bufs));
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
|
|||||||
if (length === 0) {
|
if (length === 0) {
|
||||||
controller.enqueue(new Uint8Array());
|
controller.enqueue(new Uint8Array());
|
||||||
} else if (length === 1) {
|
} else if (length === 1) {
|
||||||
controller.enqueue(bufs[0]);
|
controller.enqueue(bufs[0]!);
|
||||||
} else {
|
} else {
|
||||||
controller.enqueue(concat(bufs));
|
controller.enqueue(concat(bufs));
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,9 @@ export function mergeReadableStreams<T>(
|
|||||||
}
|
}
|
||||||
controller.enqueue(data);
|
controller.enqueue(data);
|
||||||
}
|
}
|
||||||
resolvePromises[index].resolve();
|
resolvePromises[index]!.resolve();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
resolvePromises[index].reject(error);
|
resolvePromises[index]!.reject(error);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ export class TextDelimiterStream extends TransformStream<string, string> {
|
|||||||
this.#inspectIndex++;
|
this.#inspectIndex++;
|
||||||
localIndex++;
|
localIndex++;
|
||||||
} else {
|
} else {
|
||||||
this.#matchIndex = this.#delimLPS[this.#matchIndex - 1];
|
this.#matchIndex = this.#delimLPS[this.#matchIndex - 1]!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user