@@ -19,14 +19,19 @@ import struct SystemPackage.FilePath
19
19
public protocol CacheKey : Encodable {
20
20
}
21
21
22
- extension Bool : CacheKey {
22
+ /// Types that cannot be decomposed more to be hashed
23
+ protocol LeafCacheKey : CacheKey {
24
+ func hash( with hashFunction: inout some HashFunction )
25
+ }
26
+
27
+ extension Bool : LeafCacheKey {
23
28
func hash( with hashFunction: inout some HashFunction ) {
24
29
String ( reflecting: Self . self) . hash ( with: & hashFunction)
25
30
hashFunction. update ( data: self ? [ 1 ] : [ 0 ] )
26
31
}
27
32
}
28
33
29
- extension Int : CacheKey {
34
+ extension Int : LeafCacheKey {
30
35
func hash( with hashFunction: inout some HashFunction ) {
31
36
String ( reflecting: Self . self) . hash ( with: & hashFunction)
32
37
withUnsafeBytes ( of: self ) {
@@ -35,7 +40,7 @@ extension Int: CacheKey {
35
40
}
36
41
}
37
42
38
- extension Int8 : CacheKey {
43
+ extension Int8 : LeafCacheKey {
39
44
func hash( with hashFunction: inout some HashFunction ) {
40
45
String ( reflecting: Self . self) . hash ( with: & hashFunction)
41
46
withUnsafeBytes ( of: self ) {
@@ -44,7 +49,7 @@ extension Int8: CacheKey {
44
49
}
45
50
}
46
51
47
- extension Int16 : CacheKey {
52
+ extension Int16 : LeafCacheKey {
48
53
func hash( with hashFunction: inout some HashFunction ) {
49
54
String ( reflecting: Self . self) . hash ( with: & hashFunction)
50
55
withUnsafeBytes ( of: self ) {
@@ -53,7 +58,7 @@ extension Int16: CacheKey {
53
58
}
54
59
}
55
60
56
- extension Int32 : CacheKey {
61
+ extension Int32 : LeafCacheKey {
57
62
func hash( with hashFunction: inout some HashFunction ) {
58
63
String ( reflecting: Self . self) . hash ( with: & hashFunction)
59
64
withUnsafeBytes ( of: self ) {
@@ -62,7 +67,7 @@ extension Int32: CacheKey {
62
67
}
63
68
}
64
69
65
- extension Int64 : CacheKey {
70
+ extension Int64 : LeafCacheKey {
66
71
func hash( with hashFunction: inout some HashFunction ) {
67
72
String ( reflecting: Self . self) . hash ( with: & hashFunction)
68
73
withUnsafeBytes ( of: self ) {
@@ -71,7 +76,7 @@ extension Int64: CacheKey {
71
76
}
72
77
}
73
78
74
- extension UInt : CacheKey {
79
+ extension UInt : LeafCacheKey {
75
80
func hash( with hashFunction: inout some HashFunction ) {
76
81
String ( reflecting: Self . self) . hash ( with: & hashFunction)
77
82
withUnsafeBytes ( of: self ) {
@@ -80,7 +85,7 @@ extension UInt: CacheKey {
80
85
}
81
86
}
82
87
83
- extension UInt8 : CacheKey {
88
+ extension UInt8 : LeafCacheKey {
84
89
func hash( with hashFunction: inout some HashFunction ) {
85
90
String ( reflecting: Self . self) . hash ( with: & hashFunction)
86
91
withUnsafeBytes ( of: self ) {
@@ -89,7 +94,7 @@ extension UInt8: CacheKey {
89
94
}
90
95
}
91
96
92
- extension UInt16 : CacheKey {
97
+ extension UInt16 : LeafCacheKey {
93
98
func hash( with hashFunction: inout some HashFunction ) {
94
99
String ( reflecting: Self . self) . hash ( with: & hashFunction)
95
100
withUnsafeBytes ( of: self ) {
@@ -98,7 +103,7 @@ extension UInt16: CacheKey {
98
103
}
99
104
}
100
105
101
- extension UInt32 : CacheKey {
106
+ extension UInt32 : LeafCacheKey {
102
107
func hash( with hashFunction: inout some HashFunction ) {
103
108
String ( reflecting: Self . self) . hash ( with: & hashFunction)
104
109
withUnsafeBytes ( of: self ) {
@@ -107,7 +112,7 @@ extension UInt32: CacheKey {
107
112
}
108
113
}
109
114
110
- extension UInt64 : CacheKey {
115
+ extension UInt64 : LeafCacheKey {
111
116
func hash( with hashFunction: inout some HashFunction ) {
112
117
String ( reflecting: Self . self) . hash ( with: & hashFunction)
113
118
withUnsafeBytes ( of: self ) {
@@ -116,7 +121,7 @@ extension UInt64: CacheKey {
116
121
}
117
122
}
118
123
119
- extension Float : CacheKey {
124
+ extension Float : LeafCacheKey {
120
125
func hash( with hashFunction: inout some HashFunction ) {
121
126
String ( reflecting: Self . self) . hash ( with: & hashFunction)
122
127
withUnsafeBytes ( of: self ) {
@@ -125,7 +130,7 @@ extension Float: CacheKey {
125
130
}
126
131
}
127
132
128
- extension Double : CacheKey {
133
+ extension Double : LeafCacheKey {
129
134
func hash( with hashFunction: inout some HashFunction ) {
130
135
String ( reflecting: Self . self) . hash ( with: & hashFunction)
131
136
withUnsafeBytes ( of: self ) {
@@ -134,7 +139,7 @@ extension Double: CacheKey {
134
139
}
135
140
}
136
141
137
- extension String : CacheKey {
142
+ extension String : LeafCacheKey {
138
143
func hash( with hashFunction: inout some HashFunction ) {
139
144
var t = String ( reflecting: Self . self)
140
145
t. withUTF8 {
@@ -147,21 +152,21 @@ extension String: CacheKey {
147
152
}
148
153
}
149
154
150
- extension FilePath : CacheKey {
155
+ extension FilePath : LeafCacheKey {
151
156
func hash( with hashFunction: inout some HashFunction ) {
152
157
String ( reflecting: Self . self) . hash ( with: & hashFunction)
153
158
self . string. hash ( with: & hashFunction)
154
159
}
155
160
}
156
161
157
- extension FilePath . Component : CacheKey {
162
+ extension FilePath . Component : LeafCacheKey {
158
163
func hash( with hashFunction: inout some HashFunction ) {
159
164
String ( reflecting: Self . self) . hash ( with: & hashFunction)
160
165
self . string. hash ( with: & hashFunction)
161
166
}
162
167
}
163
168
164
- extension URL : CacheKey {
169
+ extension URL : LeafCacheKey {
165
170
func hash( with hashFunction: inout some HashFunction ) {
166
171
String ( reflecting: Self . self) . hash ( with: & hashFunction)
167
172
self . description. hash ( with: & hashFunction)
0 commit comments