Skip to content

Commit e647c6a

Browse files
committed
Align rustc_metadata Table to word boundary
1 parent e114d62 commit e647c6a

File tree

1 file changed

+9
-1
lines changed
  • compiler/rustc_metadata/src/rmeta

1 file changed

+9
-1
lines changed

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,16 @@ where
172172

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

0 commit comments

Comments
 (0)