Skip to content

Commit

Permalink
fix review notes
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Mar 16, 2024
1 parent 835d4b2 commit 9241997
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2200,12 +2200,10 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
let len = d.read_usize();
let mmap = if len > 0 {
let mut mmap = MmapMut::map_anon(len).unwrap();
let mut num_bytes = 0;
for _ in 0..len {
num_bytes += (&mut mmap[..]).write(&[d.read_u8()]).unwrap();
(&mut mmap[..]).write_all(&[d.read_u8()]).unwrap();
}
mmap.flush().unwrap();
debug_assert!(len == num_bytes);
Some(mmap.make_read_only().unwrap())
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,11 @@ pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, i
// So we do not read exactly 16 bytes into the u128, just the "payload".
let uint = match endianness {
Endian::Little => {
let _ = source.read(&mut buf)?;
source.read_exact(&mut buf)?;
Ok(u128::from_le_bytes(buf))
}
Endian::Big => {
let _ = source.read(&mut buf[16 - source.len()..])?;
source.read_exact(&mut buf[16 - source.len()..])?;
Ok(u128::from_be_bytes(buf))
}
};
Expand Down
8 changes: 4 additions & 4 deletions compiler/stable_mir/src/mir/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ pub(crate) fn read_target_uint(mut bytes: &[u8]) -> Result<u128, Error> {
let mut buf = [0u8; std::mem::size_of::<u128>()];
match MachineInfo::target_endianess() {
Endian::Little => {
let _ = bytes.read(&mut buf)?;
bytes.read_exact(&mut buf)?;
Ok(u128::from_le_bytes(buf))
}
Endian::Big => {
let _ = bytes.read(&mut buf[16 - bytes.len()..])?;
bytes.read_exact(&mut buf[16 - bytes.len()..])?;
Ok(u128::from_be_bytes(buf))
}
}
Expand All @@ -72,11 +72,11 @@ pub(crate) fn read_target_int(mut bytes: &[u8]) -> Result<i128, Error> {
let mut buf = [0u8; std::mem::size_of::<i128>()];
match MachineInfo::target_endianess() {
Endian::Little => {
let _ = bytes.read(&mut buf)?;
bytes.read_exact(&mut buf)?;
Ok(i128::from_le_bytes(buf))
}
Endian::Big => {
let _ = bytes.read(&mut buf[16 - bytes.len()..])?;
bytes.read_exact(&mut buf[16 - bytes.len()..])?;
Ok(i128::from_be_bytes(buf))
}
}
Expand Down

0 comments on commit 9241997

Please sign in to comment.