Skip to content

Commit c9fd1c3

Browse files
Merge pull request #30278 from Microsoft/fasterhash
Improve performance of fallback hash function
2 parents 409e076 + 1565663 commit c9fd1c3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/compiler/sys.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ namespace ts {
88
*/
99
/* @internal */
1010
export function generateDjb2Hash(data: string): string {
11-
const chars = data.split("").map(str => str.charCodeAt(0));
12-
return `${chars.reduce((prev, curr) => ((prev << 5) + prev) + curr, 5381)}`;
11+
let acc = 5381;
12+
for (let i = 0; i < data.length; i++) {
13+
acc = ((acc << 5) + acc) + data.charCodeAt(i);
14+
}
15+
return acc.toString();
1316
}
1417

1518
/**

0 commit comments

Comments
 (0)