@@ -15,7 +15,7 @@ pub use self::DynamicContext as Context;
1515use sha2_impl:: Sha2CrateImpl ;
1616
1717#[ cfg( feature = "zero_hash_cache" ) ]
18- use lazy_static :: lazy_static ;
18+ use std :: sync :: LazyLock ;
1919
2020/// Length of a SHA256 hash in bytes.
2121pub const HASH_LEN : usize = 32 ;
@@ -193,18 +193,16 @@ impl Sha256Context for DynamicContext {
193193pub const ZERO_HASHES_MAX_INDEX : usize = 48 ;
194194
195195#[ cfg( feature = "zero_hash_cache" ) ]
196- lazy_static ! {
197- /// Cached zero hashes where `ZERO_HASHES[i]` is the hash of a Merkle tree with 2^i zero leaves.
198- pub static ref ZERO_HASHES : Vec <Vec <u8 >> = {
199- let mut hashes = vec![ vec![ 0 ; 32 ] ; ZERO_HASHES_MAX_INDEX + 1 ] ;
196+ /// Cached zero hashes where `ZERO_HASHES[i]` is the hash of a Merkle tree with 2^i zero leaves.
197+ pub static ZERO_HASHES : LazyLock < Vec < [ u8 ; HASH_LEN ] > > = LazyLock :: new ( || {
198+ let mut hashes = vec ! [ [ 0 ; HASH_LEN ] ; ZERO_HASHES_MAX_INDEX + 1 ] ;
200199
201- for i in 0 ..ZERO_HASHES_MAX_INDEX {
202- hashes[ i + 1 ] = hash32_concat( & hashes[ i] , & hashes[ i] ) [ .. ] . to_vec ( ) ;
203- }
200+ for i in 0 ..ZERO_HASHES_MAX_INDEX {
201+ hashes[ i + 1 ] = hash32_concat ( & hashes[ i] , & hashes[ i] ) ;
202+ }
204203
205- hashes
206- } ;
207- }
204+ hashes
205+ } ) ;
208206
209207#[ cfg( test) ]
210208mod tests {
@@ -231,7 +229,7 @@ mod tests {
231229
232230 #[ test]
233231 fn zero_hash_zero ( ) {
234- assert_eq ! ( ZERO_HASHES [ 0 ] , vec! [ 0 ; 32 ] ) ;
232+ assert_eq ! ( ZERO_HASHES [ 0 ] , [ 0 ; 32 ] ) ;
235233 }
236234 }
237235}
0 commit comments