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

Align rustc_metadata Table to word boundary #76620

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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