Skip to content

Commit 1c7faef

Browse files
Change hashing function to native FNV-1a implementation.
1 parent a661d39 commit 1c7faef

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/core/prompts/sections/__tests__/custom-instructions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ describe("File deduplication", () => {
16111611
vi.clearAllMocks()
16121612
})
16131613

1614-
test("should skip files with duplicate content (same MD5 hash)", async () => {
1614+
test("should skip files with duplicate content (same content hash)", async () => {
16151615
// Mock directory structure with different files having identical content
16161616
const mockEntries = [
16171617
{

src/core/prompts/sections/custom-instructions.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fs from "fs/promises"
22
import path from "path"
33
import * as os from "os"
44
import { Dirent } from "fs"
5-
import { createHash } from "crypto"
65

76
import { isLanguage } from "@roo-code/types"
87

@@ -20,10 +19,17 @@ interface FileTracker {
2019
}
2120

2221
/**
23-
* Create MD5 hash of file content
22+
* Create content hash using FNV-1a algorithm (non-cryptographic, fast, cross-platform)
2423
*/
2524
function createContentHash(content: string): string {
26-
return createHash("md5").update(content, "utf8").digest("hex")
25+
let hash = 2166136261 // FNV offset basis (32-bit)
26+
27+
for (let i = 0; i < content.length; i++) {
28+
hash ^= content.charCodeAt(i)
29+
hash = Math.imul(hash, 16777619) // FNV prime (32-bit)
30+
}
31+
32+
return (hash >>> 0).toString(16) // Convert to unsigned 32-bit hex
2733
}
2834

2935
/**

0 commit comments

Comments
 (0)