Skip to content

Commit 6861caa

Browse files
committed
small rename and refactoring
1 parent 6f38120 commit 6861caa

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/dictionary/parallel_parser.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { unreachable } from "@std/assert/unreachable";
21
import { extractResultError, ResultError } from "../compound.ts";
32
import { Position, PositionedError } from "../parser/parser_lib.ts";
43
import { HEADS } from "./parser.ts";
@@ -13,13 +12,13 @@ type WorkerError =
1312
>
1413
| Readonly<{ type: "other"; error: unknown }>;
1514

16-
function buildOffloaded(src: string): Promise<Dictionary> {
15+
function buildOffloaded(source: string): Promise<Dictionary> {
1716
return new Promise((resolve, reject) => {
1817
const worker = new Worker(
1918
new URL("./worker.ts", import.meta.url),
2019
{ type: "module" },
2120
);
22-
worker.postMessage(src);
21+
worker.postMessage(source);
2322
worker.onmessage = (event) => {
2423
resolve(event.data as Dictionary);
2524
worker.terminate();
@@ -43,24 +42,23 @@ function buildOffloaded(src: string): Promise<Dictionary> {
4342
};
4443
});
4544
}
46-
export async function parseDictionary(src: string): Promise<Dictionary> {
47-
const heads = [
48-
...[...src.matchAll(HEADS)].map((match) => match.index),
49-
src.length,
50-
];
45+
export async function parseDictionary(source: string): Promise<Dictionary> {
46+
const heads = [...source.matchAll(HEADS)].map((match) => match.index);
5147
const regionIndices = [...new Array(navigator.hardwareConcurrency).keys()]
5248
.map((index) => {
53-
const start = index * src.length / navigator.hardwareConcurrency;
49+
const start = index * source.length / navigator.hardwareConcurrency;
5450
for (const head of heads) {
5551
if (start <= head) {
5652
return head;
5753
}
5854
}
59-
unreachable();
55+
return source.length;
6056
});
6157
const jobs = regionIndices.map((index, i) => ({
6258
index: index,
63-
job: buildOffloaded(src.slice(index, regionIndices[i + 1] ?? src.length)),
59+
job: buildOffloaded(
60+
source.slice(index, regionIndices[i + 1] ?? source.length),
61+
),
6462
}));
6563
const dictionary: Dictionary = new Map();
6664
const errors: Array<ResultError> = [];

src/parser/lexer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,6 @@ const alaX = memoize((word: string) =>
203203
const xAlaX = word.then(alaX);
204204
const xAlaXInside = sequence(many(token), xAlaX);
205205

206-
export function hasXAlaX(src: string): boolean {
207-
return !xAlaXInside.parse(src).isError();
206+
export function hasXAlaX(source: string): boolean {
207+
return !xAlaXInside.parse(source).isError();
208208
}

0 commit comments

Comments
 (0)