Skip to content

Commit

Permalink
Some refactoring in fingerprint computation
Browse files Browse the repository at this point in the history
  • Loading branch information
Edoardo Pirovano authored and Edoardo Pirovano committed Jun 7, 2021
1 parent 9c13fef commit c095005
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
22 changes: 9 additions & 13 deletions lib/fingerprints.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/fingerprints.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 9 additions & 15 deletions src/fingerprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const tab = "\t".charCodeAt(0);
const space = " ".charCodeAt(0);
const lf = "\n".charCodeAt(0);
const cr = "\r".charCodeAt(0);
const EOF = 65535;
const BLOCK_SIZE = 100;
const MOD = Long.fromInt(37); // L

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

await new Promise((fulfill) => {
const readStream = fs.createReadStream(filepath, "utf8");
readStream.on("close", fulfill);
readStream.on("end", () => {
processCharacter(65535);
});
readStream.on("data", (data) => {
for (let i = 0; i < data.length; ++i)
processCharacter(data.charCodeAt(i));
});
});
const readStream = fs.createReadStream(filepath, "utf8");
for await (const data of readStream) {
for (let i = 0; i < data.length; ++i) {
processCharacter(data.charCodeAt(i));
}
}
processCharacter(EOF);

// Flush the remaining lines
for (let i = 0; i < BLOCK_SIZE; i++) {
Expand Down Expand Up @@ -274,10 +271,7 @@ export async function addFingerprints(
continue;
}

if (
typeof primaryLocation?.physicalLocation?.region?.startLine ===
"undefined"
) {
if (primaryLocation?.physicalLocation?.region?.startLine === undefined) {
// Locations without a line number are unlikely to be source files
continue;
}
Expand Down

0 comments on commit c095005

Please sign in to comment.