(
fileList: string[],
markQueryable: () => void,
)
| 93 | } |
| 94 | |
| 95 | private async buildAsync( |
| 96 | fileList: string[], |
| 97 | markQueryable: () => void, |
| 98 | ): Promise<void> { |
| 99 | const seen = new Set<string>() |
| 100 | const paths: string[] = [] |
| 101 | let chunkStart = performance.now() |
| 102 | for (let i = 0; i < fileList.length; i++) { |
| 103 | const line = fileList[i]! |
| 104 | if (line.length > 0 && !seen.has(line)) { |
| 105 | seen.add(line) |
| 106 | paths.push(line) |
| 107 | } |
| 108 | // Check every 256 iterations to amortize performance.now() overhead |
| 109 | if ((i & 0xff) === 0xff && performance.now() - chunkStart > CHUNK_MS) { |
| 110 | await yieldToEventLoop() |
| 111 | chunkStart = performance.now() |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | this.resetArrays(paths) |
| 116 | |
| 117 | chunkStart = performance.now() |
| 118 | let firstChunk = true |
| 119 | for (let i = 0; i < paths.length; i++) { |
| 120 | this.indexPath(i) |
| 121 | if ((i & 0xff) === 0xff && performance.now() - chunkStart > CHUNK_MS) { |
| 122 | this.readyCount = i + 1 |
| 123 | if (firstChunk) { |
| 124 | markQueryable() |
| 125 | firstChunk = false |
| 126 | } |
| 127 | await yieldToEventLoop() |
| 128 | chunkStart = performance.now() |
| 129 | } |
| 130 | } |
| 131 | this.readyCount = paths.length |
| 132 | markQueryable() |
| 133 | } |
| 134 | |
| 135 | private buildIndex(paths: string[]): void { |
| 136 | this.resetArrays(paths) |
no test coverage detected