@@ -4,8 +4,6 @@ use std::hash::{Hash, Hasher};
4
4
use std:: ops:: Deref ;
5
5
use std:: ptr;
6
6
7
- use crate :: fingerprint:: Fingerprint ;
8
-
9
7
mod private {
10
8
#[ derive( Clone , Copy , Debug ) ]
11
9
pub struct PrivateZst ;
@@ -110,86 +108,5 @@ where
110
108
}
111
109
}
112
110
113
- /// A helper type that you can wrap round your own type in order to automatically
114
- /// cache the stable hash on creation and not recompute it whenever the stable hash
115
- /// of the type is computed.
116
- /// This is only done in incremental mode. You can also opt out of caching by using
117
- /// StableHash::ZERO for the hash, in which case the hash gets computed each time.
118
- /// This is useful if you have values that you intern but never (can?) use for stable
119
- /// hashing.
120
- #[ derive( Copy , Clone ) ]
121
- pub struct WithCachedTypeInfo < T > {
122
- pub internee : T ,
123
- pub stable_hash : Fingerprint ,
124
- }
125
-
126
- impl < T : PartialEq > PartialEq for WithCachedTypeInfo < T > {
127
- #[ inline]
128
- fn eq ( & self , other : & Self ) -> bool {
129
- self . internee . eq ( & other. internee )
130
- }
131
- }
132
-
133
- impl < T : Eq > Eq for WithCachedTypeInfo < T > { }
134
-
135
- impl < T : Ord > PartialOrd for WithCachedTypeInfo < T > {
136
- fn partial_cmp ( & self , other : & WithCachedTypeInfo < T > ) -> Option < Ordering > {
137
- Some ( self . internee . cmp ( & other. internee ) )
138
- }
139
- }
140
-
141
- impl < T : Ord > Ord for WithCachedTypeInfo < T > {
142
- fn cmp ( & self , other : & WithCachedTypeInfo < T > ) -> Ordering {
143
- self . internee . cmp ( & other. internee )
144
- }
145
- }
146
-
147
- impl < T > Deref for WithCachedTypeInfo < T > {
148
- type Target = T ;
149
-
150
- #[ inline]
151
- fn deref ( & self ) -> & T {
152
- & self . internee
153
- }
154
- }
155
-
156
- impl < T : Hash > Hash for WithCachedTypeInfo < T > {
157
- #[ inline]
158
- fn hash < H : Hasher > ( & self , s : & mut H ) {
159
- if self . stable_hash != Fingerprint :: ZERO {
160
- self . stable_hash . hash ( s)
161
- } else {
162
- self . internee . hash ( s)
163
- }
164
- }
165
- }
166
-
167
- impl < T : HashStable < CTX > , CTX > HashStable < CTX > for WithCachedTypeInfo < T > {
168
- fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
169
- if self . stable_hash == Fingerprint :: ZERO || cfg ! ( debug_assertions) {
170
- // No cached hash available. This can only mean that incremental is disabled.
171
- // We don't cache stable hashes in non-incremental mode, because they are used
172
- // so rarely that the performance actually suffers.
173
-
174
- // We need to build the hash as if we cached it and then hash that hash, as
175
- // otherwise the hashes will differ between cached and non-cached mode.
176
- let stable_hash: Fingerprint = {
177
- let mut hasher = StableHasher :: new ( ) ;
178
- self . internee . hash_stable ( hcx, & mut hasher) ;
179
- hasher. finish ( )
180
- } ;
181
- if cfg ! ( debug_assertions) && self . stable_hash != Fingerprint :: ZERO {
182
- assert_eq ! (
183
- stable_hash, self . stable_hash,
184
- "cached stable hash does not match freshly computed stable hash"
185
- ) ;
186
- }
187
- stable_hash. hash_stable ( hcx, hasher) ;
188
- } else {
189
- self . stable_hash . hash_stable ( hcx, hasher) ;
190
- }
191
- }
192
- }
193
-
194
111
#[ cfg( test) ]
195
112
mod tests;
0 commit comments