Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disk bucket: get mut right on get_mut_cell_slice #30972

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

jeffwashington
Copy link
Contributor

Problem

see #30711

get_mut_cell_slice() should have taken &mut self but took &self due to borrow checker difficulties.

Summary of Changes

correctly use &mut self

Fixes #

@@ -212,8 +212,7 @@ impl<O: BucketOccupied> BucketStorage<O> {
Self::get_mut_from_parts(item_slice)
}

#[allow(clippy::mut_from_ref)]
pub fn get_mut_cell_slice<T: Sized>(&self, ix: u64, len: u64) -> &mut [T] {
pub fn get_mut_cell_slice<T: Sized>(&mut self, ix: u64, len: u64) -> &mut [T] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this for the impl:

    pub fn get_mut_cell_slice<T: Sized>(&mut self, ix: u64, len: u64) -> &mut [T] {
        let start = self.get_start_offset_no_header(ix);
        let end = start + std::mem::size_of::<T>() * len as usize;
        //debug!("GET mut slice {} {}", start, end);
        let item_slice = &mut self.mmap[start..end];
        let item = item_slice.as_mut_ptr() as *mut T;
        unsafe { std::slice::from_raw_parts_mut(item, len as usize) }
    }

And then a subsequent PR can change get_mut() to call this fn with len = 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will handle in a subsequent PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov
Copy link

codecov bot commented Mar 29, 2023

Codecov Report

Merging #30972 (355f1b2) into master (2646fb7) will increase coverage by 0.0%.
The diff coverage is 67.8%.

@@           Coverage Diff           @@
##           master   #30972   +/-   ##
=======================================
  Coverage    81.5%    81.5%           
=======================================
  Files         728      728           
  Lines      205467   205454   -13     
=======================================
+ Hits       167532   167543   +11     
+ Misses      37935    37911   -24     

Copy link
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@jeffwashington jeffwashington merged commit 38e054f into solana-labs:master Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants