Skip to content

Commit 666fc8a

Browse files
committed
perf: cache InvocationKey hash values at construction time
Signed-off-by: Ari Rubinstein <arirubinstein@users.noreply.github.com>
1 parent 591b71c commit 666fc8a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Sources/Rego/IREvaluator.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ let localIdxData = Local(1)
1212
struct InvocationKey: Hashable {
1313
let funcName: String
1414
let args: [IR.Operand]
15+
private let cachedHashValue: Int
16+
17+
init(funcName: String, args: [IR.Operand]) {
18+
self.funcName = funcName
19+
self.args = args
20+
var hasher = Hasher()
21+
hasher.combine(funcName)
22+
hasher.combine(args)
23+
self.cachedHashValue = hasher.finalize()
24+
}
25+
26+
func hash(into hasher: inout Hasher) {
27+
hasher.combine(cachedHashValue)
28+
}
1529
}
1630

1731
/// MemoCache is a memoization cache of plan invocations

0 commit comments

Comments
 (0)