ReviewOS

also looking at this

stacks/dtsx

chore(deps): update all non-major dependencies

#2997
Closed renovate[bot] wants to merge renovate/all-minor-patch into main
29 files +1047 -444
packages/dtsx/src/extractor/cache.tsmodified+3-22
Changes to packages/dtsx/src/extractor/cache.ts
@@ -5,6 +5,9 @@
55
66import type { SourceFile } from 'typescript'
77import { createSourceFile, ScriptKind, ScriptTarget } from 'typescript'
8import { hashContent } from './hash'
9
10export { hashContent } from './hash'
811
912/**
1013 * Cache for parsed SourceFile objects to avoid re-parsing
@@ -12,11 +15,6 @@ import { createSourceFile, ScriptKind, ScriptTarget } from 'typescript'
1215 */
1316const sourceFileCache = new Map<string, { sourceFile: SourceFile, contentHash: number | bigint, lastAccess: number }>()
1417
15/**
16 * Whether Bun.hash is available (much faster than JS hash)
17 */
18const hasBunHash = typeof globalThis.Bun?.hash === 'function'
19
2018/**
2119 * Pending async parse operations to prevent duplicate parsing
2220 */
@@ -50,23 +48,6 @@ export interface AsyncParseConfig {
5048 */
5149const MAX_CACHE_SIZE = 100
5250
53/**
54 * Fast hash function for content comparison.
55 * Uses Bun.hash (native wyhash) when available, falls back to JS implementation.
56 */
57export function hashContent(content: string): number | bigint {
58 if (hasBunHash) {
59 return Bun.hash(content)
60 }
61 let hash = 0
62 for (let i = 0; i < content.length; i++) {
63 const char = content.charCodeAt(i)
64 hash = ((hash << 5) - hash) + char
65 hash = hash & hash // Convert to 32-bit integer
66 }
67 return hash
68}
69
7051/**
7152 * Evict oldest entry if cache exceeds max size
7253 * Uses O(n) scan instead of O(n log n) sort since we add one entry at a time