1- import { unreachable } from "@std/assert/unreachable" ;
21import { extractResultError , ResultError } from "../compound.ts" ;
32import { Position , PositionedError } from "../parser/parser_lib.ts" ;
43import { 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 > = [ ] ;
0 commit comments