Skip to content

Commit

Permalink
Make clearer that shrink_to_fit does not copy data
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Passaro <[email protected]>
  • Loading branch information
passaro committed Oct 26, 2023
1 parent 02ce1c2 commit a20573b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mountpoint-s3/src/checksums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use thiserror::Error;
#[derive(Clone, Debug)]
pub struct ChecksummedBytes {
orig_bytes: Bytes,
/// Always a subslice of `orig_bytes`
curr_slice: Bytes,
/// Checksum for `orig_bytes`
checksum: Crc32c,
Expand Down Expand Up @@ -88,7 +89,12 @@ impl ChecksummedBytes {
return Ok(self.clone());
}

let result = Self::from_bytes(self.curr_slice.clone());
// Note that no data is copied: `bytes` still points to a subslice of `orig_bytes`.
let bytes = self.curr_slice.clone();
let checksum = crc32c::checksum(&bytes);
let result = Self::new(bytes, checksum);

// Check the integrity of the whole buffer.
self.validate()?;
Ok(result)
}
Expand Down

0 comments on commit a20573b

Please sign in to comment.