Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove deprecated BytesList() in readDelim() #3726

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions io/read_delim.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { BytesList } from "../bytes/bytes_list.ts";
import { concat } from "../bytes/concat.ts";
import type { Reader } from "../types.d.ts";

/** Generate longest proper prefix which is also suffix array. */
Expand Down Expand Up @@ -37,7 +37,7 @@ export async function* readDelim(
// Avoid unicode problems
const delimLen = delim.length;
const delimLPS = createLPS(delim);
const chunks = new BytesList();
let chunks = new Uint8Array();
const bufSize = Math.max(1024, delimLen + 1);

// Modified KMP
Expand All @@ -48,15 +48,15 @@ export async function* readDelim(
const result = await reader.read(inspectArr);
if (result === null) {
// Yield last chunk.
yield chunks.concat();
yield chunks;
return;
} else if (result < 0) {
// Discard all remaining and silently fail.
return;
}
chunks.add(inspectArr, 0, result);
chunks = concat(chunks, inspectArr.slice(0, result));
let localIndex = 0;
while (inspectIndex < chunks.size()) {
while (inspectIndex < chunks.length) {
if (inspectArr[localIndex] === delim[matchIndex]) {
inspectIndex++;
localIndex++;
Expand All @@ -67,7 +67,7 @@ export async function* readDelim(
const readyBytes = chunks.slice(0, matchEnd);
yield readyBytes;
// Reset match, different from KMP.
chunks.shift(inspectIndex);
chunks = chunks.slice(inspectIndex);
inspectIndex = 0;
matchIndex = 0;
}
Expand Down