Skip to content

Commit

Permalink
Align rustc_metadata Table to word boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
ishitatsuyuki committed Sep 12, 2020
1 parent e114d62 commit e647c6a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/rustc_metadata/src/rmeta/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,16 @@ where

pub(crate) fn encode(&self, buf: &mut Encoder) -> Lazy<Table<I, T>> {
let pos = buf.position();
// Since all of the data are serialized as u32, adding some padding
// should make encoding/decoding slightly faster.
let pad = (4 - (pos % 4)) % 4;
let pad_bytes = [0, 0, 0];
buf.emit_raw_bytes(&pad_bytes[..pad]);
buf.emit_raw_bytes(&self.bytes);
Lazy::from_position_and_meta(NonZeroUsize::new(pos as usize).unwrap(), self.bytes.len())
Lazy::from_position_and_meta(
NonZeroUsize::new(pos as usize + pad).unwrap(),
self.bytes.len(),
)
}
}

Expand Down

0 comments on commit e647c6a

Please sign in to comment.