@@ -336,7 +336,8 @@ impl CumulativeHashesFromFiles {
336
336
}
337
337
338
338
// return the biggest hash data possible that starts at the overall index 'start'
339
- fn get_data ( & self , start : usize ) -> Arc < Vec < Hash > > {
339
+ // start is the index of hashes
340
+ fn get_data ( & self , start : usize ) -> Arc < Vec < u8 > > {
340
341
let ( start, offset) = self . cumulative . find ( start) ;
341
342
let data_source_index = offset. index [ 0 ] ;
342
343
let mut data = self . readers [ data_source_index] . lock ( ) . unwrap ( ) ;
@@ -348,8 +349,7 @@ impl CumulativeHashesFromFiles {
348
349
349
350
let mut result_bytes: Vec < u8 > = vec ! [ ] ;
350
351
data. read_to_end ( & mut result_bytes) . unwrap ( ) ;
351
- let result: Vec < Hash > = bytemuck:: cast_slice ( & result_bytes) . to_vec ( ) ;
352
- Arc :: new ( result)
352
+ Arc :: new ( result_bytes)
353
353
}
354
354
}
355
355
@@ -550,8 +550,8 @@ impl<'a> AccountsHasher<'a> {
550
550
specific_level_count : Option < usize > ,
551
551
) -> ( Hash , Vec < Hash > )
552
552
where
553
- // returns a vec hashes starting at the given overall index
554
- F : Fn ( usize ) -> Arc < Vec < T > > + std:: marker:: Sync ,
553
+ // returns a vec hash bytes starting at the given overall index
554
+ F : Fn ( usize ) -> Arc < Vec < u8 > > + std:: marker:: Sync ,
555
555
T : AsRef < [ u8 ] > + std:: marker:: Send + std:: marker:: Sync + bytemuck:: Pod ,
556
556
{
557
557
if total_hashes == 0 {
@@ -570,7 +570,8 @@ impl<'a> AccountsHasher<'a> {
570
570
let chunks = Self :: div_ceil ( total_hashes, num_hashes_per_chunk) ;
571
571
572
572
// initial fetch - could return entire slice
573
- let data = get_hash_slice_starting_at_index ( 0 ) ;
573
+ let data_bytes = get_hash_slice_starting_at_index ( 0 ) ;
574
+ let data: & [ T ] = bytemuck:: cast_slice ( & data_bytes) ;
574
575
575
576
let data_len = data. len ( ) ;
576
577
@@ -593,7 +594,8 @@ impl<'a> AccountsHasher<'a> {
593
594
// if we exhaust our data, then we will request a new slice, and data_index resets to 0, the beginning of the new slice
594
595
let mut data_index = start_index;
595
596
// source data, which we may refresh when we exhaust
596
- let mut data = data. clone ( ) ;
597
+ let mut data_bytes = data_bytes. clone ( ) ;
598
+ let mut data: & [ T ] = bytemuck:: cast_slice ( & data_bytes) ;
597
599
// len of the source data
598
600
let mut data_len = data_len;
599
601
@@ -603,7 +605,8 @@ impl<'a> AccountsHasher<'a> {
603
605
for i in start_index..end_index {
604
606
if data_index >= data_len {
605
607
// we exhausted our data, fetch next slice starting at i
606
- data = get_hash_slice_starting_at_index ( i) ;
608
+ data_bytes = get_hash_slice_starting_at_index ( i) ;
609
+ data = bytemuck:: cast_slice ( & data_bytes) ;
607
610
data_len = data. len ( ) ;
608
611
data_index = 0 ;
609
612
}
@@ -658,7 +661,8 @@ impl<'a> AccountsHasher<'a> {
658
661
for _k in 0 ..end {
659
662
if data_index >= data_len {
660
663
// we exhausted our data, fetch next slice starting at i
661
- data = get_hash_slice_starting_at_index ( i) ;
664
+ data_bytes = get_hash_slice_starting_at_index ( i) ;
665
+ data = bytemuck:: cast_slice ( & data_bytes) ;
662
666
data_len = data. len ( ) ;
663
667
data_index = 0 ;
664
668
}
@@ -1318,7 +1322,7 @@ impl<'a> AccountsHasher<'a> {
1318
1322
1319
1323
let _guard = self . active_stats . activate ( ActiveStatItem :: HashMerkleTree ) ;
1320
1324
let mut hash_time = Measure :: start ( "hash" ) ;
1321
- let ( hash, _) = Self :: compute_merkle_root_from_start (
1325
+ let ( hash, _) = Self :: compute_merkle_root_from_start :: < _ , Hash > (
1322
1326
cumulative. total_count ( ) ,
1323
1327
MERKLE_FANOUT ,
1324
1328
None ,
@@ -1636,7 +1640,8 @@ mod tests {
1636
1640
let mut cumulative_start = start;
1637
1641
// read all data
1638
1642
while retrieved. len ( ) < ( len - start) {
1639
- let this_one = cumulative. get_data ( cumulative_start) ;
1643
+ let this_one_bytes = cumulative. get_data ( cumulative_start) ;
1644
+ let this_one = bytemuck:: cast_slice ( & this_one_bytes) ;
1640
1645
retrieved. extend ( this_one. iter ( ) ) ;
1641
1646
cumulative_start += this_one. len ( ) ;
1642
1647
assert_ne ! ( 0 , this_one. len( ) ) ;
0 commit comments