Skip to content

Commit c385cbe

Browse files
devxoulkzaher
authored andcommitted
Memoize hashValue in Diff.swift
1 parent a519ef6 commit c385cbe

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/Differentiator/Diff.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,15 @@ public enum Diff {
129129
private struct OptimizedIdentity<E: Hashable> : Hashable {
130130

131131
let identity: UnsafePointer<E>
132+
private let cachedHashValue: Int
132133

133134
init(_ identity: UnsafePointer<E>) {
134135
self.identity = identity
136+
self.cachedHashValue = identity.pointee.hashValue
135137
}
136138

137139
func hash(into hasher: inout Hasher) {
138-
hasher.combine(self.identity.pointee.hashValue)
140+
hasher.combine(self.cachedHashValue)
139141
}
140142

141143
static func == (lhs: OptimizedIdentity<E>, rhs: OptimizedIdentity<E>) -> Bool {

0 commit comments

Comments
 (0)