Some refactoring in fingerprint computation
This commit is contained in:
parent
9c13fefc68
commit
c09500540c
3 changed files with 19 additions and 29 deletions
22
lib/fingerprints.js
generated
22
lib/fingerprints.js
generated
|
|
@ -16,6 +16,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_1.default.fromInt(37); // L
|
||||
// Compute the starting point for the hash mod
|
||||
|
|
@ -109,17 +110,13 @@ async function hash(callback, filepath) {
|
|||
}
|
||||
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++) {
|
||||
if (lineNumbers[index] !== -1) {
|
||||
|
|
@ -232,8 +229,7 @@ async function addFingerprints(sarifContents, checkoutPath, logger) {
|
|||
logger.debug(`Unable to compute fingerprint for invalid location: ${JSON.stringify(primaryLocation)}`);
|
||||
continue;
|
||||
}
|
||||
if (typeof ((_e = (_d = (_c = primaryLocation) === null || _c === void 0 ? void 0 : _c.physicalLocation) === null || _d === void 0 ? void 0 : _d.region) === null || _e === void 0 ? void 0 : _e.startLine) ===
|
||||
"undefined") {
|
||||
if (((_e = (_d = (_c = primaryLocation) === null || _c === void 0 ? void 0 : _c.physicalLocation) === null || _d === void 0 ? void 0 : _d.region) === null || _e === void 0 ? void 0 : _e.startLine) === undefined) {
|
||||
// Locations without a line number are unlikely to be source files
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -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
|
||||
|
||||
|
|
@ -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++) {
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue