Skip to content

Commit d687a2c

Browse files
committed
remove copy
1 parent c572244 commit d687a2c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

accounts-db/src/accounts_hash.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ impl CumulativeHashesFromFiles {
336336
}
337337

338338
// 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>> {
340341
let (start, offset) = self.cumulative.find(start);
341342
let data_source_index = offset.index[0];
342343
let mut data = self.readers[data_source_index].lock().unwrap();
@@ -348,8 +349,7 @@ impl CumulativeHashesFromFiles {
348349

349350
let mut result_bytes: Vec<u8> = vec![];
350351
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)
353353
}
354354
}
355355

@@ -550,8 +550,8 @@ impl<'a> AccountsHasher<'a> {
550550
specific_level_count: Option<usize>,
551551
) -> (Hash, Vec<Hash>)
552552
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,
555555
T: AsRef<[u8]> + std::marker::Send + std::marker::Sync + bytemuck::Pod,
556556
{
557557
if total_hashes == 0 {
@@ -570,7 +570,8 @@ impl<'a> AccountsHasher<'a> {
570570
let chunks = Self::div_ceil(total_hashes, num_hashes_per_chunk);
571571

572572
// 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);
574575

575576
let data_len = data.len();
576577

@@ -593,7 +594,8 @@ impl<'a> AccountsHasher<'a> {
593594
// if we exhaust our data, then we will request a new slice, and data_index resets to 0, the beginning of the new slice
594595
let mut data_index = start_index;
595596
// 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);
597599
// len of the source data
598600
let mut data_len = data_len;
599601

@@ -603,7 +605,8 @@ impl<'a> AccountsHasher<'a> {
603605
for i in start_index..end_index {
604606
if data_index >= data_len {
605607
// 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);
607610
data_len = data.len();
608611
data_index = 0;
609612
}
@@ -658,7 +661,8 @@ impl<'a> AccountsHasher<'a> {
658661
for _k in 0..end {
659662
if data_index >= data_len {
660663
// 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);
662666
data_len = data.len();
663667
data_index = 0;
664668
}
@@ -1318,7 +1322,7 @@ impl<'a> AccountsHasher<'a> {
13181322

13191323
let _guard = self.active_stats.activate(ActiveStatItem::HashMerkleTree);
13201324
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>(
13221326
cumulative.total_count(),
13231327
MERKLE_FANOUT,
13241328
None,
@@ -1636,7 +1640,8 @@ mod tests {
16361640
let mut cumulative_start = start;
16371641
// read all data
16381642
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);
16401645
retrieved.extend(this_one.iter());
16411646
cumulative_start += this_one.len();
16421647
assert_ne!(0, this_one.len());

0 commit comments

Comments
 (0)