From 6688b03865ed727fb71c2f14bca02dfb403eba1f Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 9 Apr 2019 21:04:21 +0300 Subject: [PATCH] proc_macro: stop using LEB128 for RPC. --- src/libproc_macro/bridge/rpc.rs | 36 ++++++++++++--------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/libproc_macro/bridge/rpc.rs b/src/libproc_macro/bridge/rpc.rs index 4289f33ffd5..5018be74f89 100644 --- a/src/libproc_macro/bridge/rpc.rs +++ b/src/libproc_macro/bridge/rpc.rs @@ -24,32 +24,22 @@ pub(super) trait DecodeMut<'a, 's, S>: Sized { } macro_rules! rpc_encode_decode { - (uleb128 $ty:ty) => { + (le $ty:ty) => { impl Encode for $ty { - fn encode(mut self, w: &mut Writer, s: &mut S) { - let mut byte = 0x80; - while byte & 0x80 != 0 { - byte = (self & 0x7f) as u8; - self >>= 7; - if self != 0 { - byte |= 0x80; - } - byte.encode(w, s); - } + fn encode(self, w: &mut Writer, _: &mut S) { + w.write_all(&self.to_le_bytes()).unwrap(); } } impl DecodeMut<'_, '_, S> for $ty { - fn decode(r: &mut Reader<'_>, s: &mut S) -> Self { - let mut byte = 0x80; - let mut v = 0; - let mut shift = 0; - while byte & 0x80 != 0 { - byte = u8::decode(r, s); - v |= ((byte & 0x7f) as Self) << shift; - shift += 7; - } - v + fn decode(r: &mut Reader<'_>, _: &mut S) -> Self { + const N: usize = ::std::mem::size_of::<$ty>(); + + let mut bytes = [0; N]; + bytes.copy_from_slice(&r[..N]); + *r = &r[N..]; + + Self::from_le_bytes(bytes) } } }; @@ -136,8 +126,8 @@ impl DecodeMut<'_, '_, S> for u8 { } } -rpc_encode_decode!(uleb128 u32); -rpc_encode_decode!(uleb128 usize); +rpc_encode_decode!(le u32); +rpc_encode_decode!(le usize); impl Encode for bool { fn encode(self, w: &mut Writer, s: &mut S) {