perf(coding-agent): optimized hash computation and simplified conditional logic across tools

- Optimized line hash computation by precomputing hex lookup table and using bitwise operations instead of string formatting.
- Simplified conditional logic in read tool for hash and line number configuration.
- Refactored react-edit-benchmark model/provider parsing to use concise ternary operator.
This commit is contained in:
can1357
2026-02-10 16:42:49 +01:00
parent b95ff1abff
commit dbec361e6b
3 changed files with 11 additions and 15 deletions
+3 -1
View File
@@ -14,6 +14,8 @@
import type { HashlineEdit, HashMismatch } from "./types";
const HEX3 = Array.from({ length: 0xfff + 1 }, (_, i) => i.toString(16).padStart(3, "0"));
/**
* Compute the 4-character hex hash of a single line.
*
@@ -23,7 +25,7 @@ import type { HashlineEdit, HashMismatch } from "./types";
* The line input should not include a trailing newline.
*/
export function computeLineHash(idx: number, line: string): string {
return Bun.hash.xxHash64(line, BigInt(idx)).toString(16).padStart(16, "0").slice(0, 4);
return HEX3[Number(Bun.hash.xxHash64(line, BigInt(idx))) & 0xfff];
}
/**