@@ -332,7 +332,8 @@ impl CumulativeHashesFromFiles {
332
332
}
333
333
334
334
// return the biggest hash data possible that starts at the overall index 'start'
335
- fn get_data ( & self , start : usize ) -> Arc < Vec < Hash > > {
335
+ // start is the index of hashes
336
+ fn get_data ( & self , start : usize ) -> Arc < Vec < u8 > > {
336
337
let ( start, offset) = self . cumulative . find ( start) ;
337
338
let data_source_index = offset. index [ 0 ] ;
338
339
let mut data = self . readers [ data_source_index] . lock ( ) . unwrap ( ) ;
@@ -344,8 +345,7 @@ impl CumulativeHashesFromFiles {
344
345
345
346
let mut result_bytes: Vec < u8 > = vec ! [ ] ;
346
347
data. read_to_end ( & mut result_bytes) . unwrap ( ) ;
347
- let result: Vec < Hash > = bytemuck:: cast_slice ( & result_bytes) . to_vec ( ) ;
348
- Arc :: new ( result)
348
+ Arc :: new ( result_bytes)
349
349
}
350
350
}
351
351
@@ -546,8 +546,8 @@ impl<'a> AccountsHasher<'a> {
546
546
specific_level_count : Option < usize > ,
547
547
) -> ( Hash , Vec < Hash > )
548
548
where
549
- // returns a vec hashes starting at the given overall index
550
- F : Fn ( usize ) -> Arc < Vec < T > > + std:: marker:: Sync ,
549
+ // returns a vec hash bytes starting at the given overall index
550
+ F : Fn ( usize ) -> Arc < Vec < u8 > > + std:: marker:: Sync ,
551
551
T : AsRef < [ u8 ] > + std:: marker:: Send + std:: marker:: Sync + bytemuck:: Pod ,
552
552
{
553
553
if total_hashes == 0 {
@@ -566,7 +566,8 @@ impl<'a> AccountsHasher<'a> {
566
566
let chunks = Self :: div_ceil ( total_hashes, num_hashes_per_chunk) ;
567
567
568
568
// initial fetch - could return entire slice
569
- let data = get_hash_slice_starting_at_index ( 0 ) ;
569
+ let data_bytes = get_hash_slice_starting_at_index ( 0 ) ;
570
+ let data: & [ T ] = bytemuck:: cast_slice ( & data_bytes) ;
570
571
571
572
let data_len = data. len ( ) ;
572
573
@@ -589,7 +590,8 @@ impl<'a> AccountsHasher<'a> {
589
590
// if we exhaust our data, then we will request a new slice, and data_index resets to 0, the beginning of the new slice
590
591
let mut data_index = start_index;
591
592
// source data, which we may refresh when we exhaust
592
- let mut data = data. clone ( ) ;
593
+ let mut data_bytes = data_bytes. clone ( ) ;
594
+ let mut data: & [ T ] = bytemuck:: cast_slice ( & data_bytes) ;
593
595
// len of the source data
594
596
let mut data_len = data_len;
595
597
@@ -599,7 +601,8 @@ impl<'a> AccountsHasher<'a> {
599
601
for i in start_index..end_index {
600
602
if data_index >= data_len {
601
603
// we exhausted our data, fetch next slice starting at i
602
- data = get_hash_slice_starting_at_index ( i) ;
604
+ data_bytes = get_hash_slice_starting_at_index ( i) ;
605
+ data = bytemuck:: cast_slice ( & data_bytes) ;
603
606
data_len = data. len ( ) ;
604
607
data_index = 0 ;
605
608
}
@@ -654,7 +657,8 @@ impl<'a> AccountsHasher<'a> {
654
657
for _k in 0 ..end {
655
658
if data_index >= data_len {
656
659
// we exhausted our data, fetch next slice starting at i
657
- data = get_hash_slice_starting_at_index ( i) ;
660
+ data_bytes = get_hash_slice_starting_at_index ( i) ;
661
+ data = bytemuck:: cast_slice ( & data_bytes) ;
658
662
data_len = data. len ( ) ;
659
663
data_index = 0 ;
660
664
}
@@ -1314,7 +1318,7 @@ impl<'a> AccountsHasher<'a> {
1314
1318
1315
1319
let _guard = self . active_stats . activate ( ActiveStatItem :: HashMerkleTree ) ;
1316
1320
let mut hash_time = Measure :: start ( "hash" ) ;
1317
- let ( hash, _) = Self :: compute_merkle_root_from_start (
1321
+ let ( hash, _) = Self :: compute_merkle_root_from_start :: < _ , Hash > (
1318
1322
cumulative. total_count ( ) ,
1319
1323
MERKLE_FANOUT ,
1320
1324
None ,
@@ -1628,7 +1632,8 @@ mod tests {
1628
1632
let mut cumulative_start = start;
1629
1633
// read all data
1630
1634
while retrieved. len ( ) < ( len - start) {
1631
- let this_one = cumulative. get_data ( cumulative_start) ;
1635
+ let this_one_bytes = cumulative. get_data ( cumulative_start) ;
1636
+ let this_one = bytemuck:: cast_slice ( & this_one_bytes) ;
1632
1637
retrieved. extend ( this_one. iter ( ) ) ;
1633
1638
cumulative_start += this_one. len ( ) ;
1634
1639
assert_ne ! ( 0 , this_one. len( ) ) ;
0 commit comments