Skip to content

Commit c095005

Browse files
Some refactoring in fingerprint computation
1 parent 9c13fef commit c095005

3 files changed

Lines changed: 19 additions & 29 deletions

File tree

lib/fingerprints.js

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/fingerprints.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fingerprints.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const tab = "\t".charCodeAt(0);
88
const space = " ".charCodeAt(0);
99
const lf = "\n".charCodeAt(0);
1010
const cr = "\r".charCodeAt(0);
11+
const EOF = 65535;
1112
const BLOCK_SIZE = 100;
1213
const MOD = Long.fromInt(37); // L
1314

@@ -114,17 +115,13 @@ export async function hash(callback: hashCallback, filepath: string) {
114115
updateHash(current);
115116
};
116117

117-
await new Promise((fulfill) => {
118-
const readStream = fs.createReadStream(filepath, "utf8");
119-
readStream.on("close", fulfill);
120-
readStream.on("end", () => {
121-
processCharacter(65535);
122-
});
123-
readStream.on("data", (data) => {
124-
for (let i = 0; i < data.length; ++i)
125-
processCharacter(data.charCodeAt(i));
126-
});
127-
});
118+
const readStream = fs.createReadStream(filepath, "utf8");
119+
for await (const data of readStream) {
120+
for (let i = 0; i < data.length; ++i) {
121+
processCharacter(data.charCodeAt(i));
122+
}
123+
}
124+
processCharacter(EOF);
128125

129126
// Flush the remaining lines
130127
for (let i = 0; i < BLOCK_SIZE; i++) {
@@ -274,10 +271,7 @@ export async function addFingerprints(
274271
continue;
275272
}
276273

277-
if (
278-
typeof primaryLocation?.physicalLocation?.region?.startLine ===
279-
"undefined"
280-
) {
274+
if (primaryLocation?.physicalLocation?.region?.startLine === undefined) {
281275
// Locations without a line number are unlikely to be source files
282276
continue;
283277
}

0 commit comments

Comments
 (0)