From 7e299563dfeb65fa7707fd37aadc4d6c55c1c5b2 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 14 May 2018 11:22:10 +0000 Subject: [PATCH] firmware: mark many functions in libio as #[inline]. --- artiq/firmware/libio/lib.rs | 10 +++++++++- artiq/firmware/libio/proto.rs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/artiq/firmware/libio/lib.rs b/artiq/firmware/libio/lib.rs index 631269ddb..ecfe51341 100644 --- a/artiq/firmware/libio/lib.rs +++ b/artiq/firmware/libio/lib.rs @@ -105,27 +105,32 @@ pub struct Cursor { } impl Cursor { + #[inline] pub fn new(inner: T) -> Cursor { Cursor { inner, pos: 0 } } + #[inline] pub fn into_inner(self) -> T { self.inner } + #[inline] pub fn get_ref(&self) -> &T { &self.inner } + #[inline] pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + #[inline] pub fn position(&self) -> usize { self.pos - } + #[inline] pub fn set_position(&mut self, pos: usize) { self.pos = pos } @@ -155,6 +160,7 @@ impl> Write for Cursor { Ok(len) } + #[inline] fn flush(&mut self) -> result::Result<(), Self::FlushError> { Ok(()) } @@ -165,11 +171,13 @@ impl> Write for Cursor { type WriteError = !; type FlushError = !; + #[inline] fn write(&mut self, buf: &[u8]) -> result::Result { self.inner.extend(buf); Ok(buf.len()) } + #[inline] fn flush(&mut self) -> result::Result<(), Self::FlushError> { Ok(()) } diff --git a/artiq/firmware/libio/proto.rs b/artiq/firmware/libio/proto.rs index eaf0c3042..f8c52e1e7 100644 --- a/artiq/firmware/libio/proto.rs +++ b/artiq/firmware/libio/proto.rs @@ -7,35 +7,41 @@ pub trait ProtoRead { fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Self::ReadError>; + #[inline] fn read_u8(&mut self) -> Result { let mut bytes = [0; 1]; self.read_exact(&mut bytes)?; Ok(bytes[0]) } + #[inline] fn read_u16(&mut self) -> Result { let mut bytes = [0; 2]; self.read_exact(&mut bytes)?; Ok(NetworkEndian::read_u16(&bytes)) } + #[inline] fn read_u32(&mut self) -> Result { let mut bytes = [0; 4]; self.read_exact(&mut bytes)?; Ok(NetworkEndian::read_u32(&bytes)) } + #[inline] fn read_u64(&mut self) -> Result { let mut bytes = [0; 8]; self.read_exact(&mut bytes)?; Ok(NetworkEndian::read_u64(&bytes)) } + #[inline] fn read_bool(&mut self) -> Result { Ok(self.read_u8()? != 0) } #[cfg(feature = "alloc")] + #[inline] fn read_bytes(&mut self) -> Result<::alloc::Vec, Self::ReadError> { let length = self.read_u32()?; let mut value = vec![0; length as usize]; @@ -55,61 +61,72 @@ pub trait ProtoWrite { fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::WriteError>; + #[inline] fn write_u8(&mut self, value: u8) -> Result<(), Self::WriteError> { let bytes = [value; 1]; self.write_all(&bytes) } + #[inline] fn write_i8(&mut self, value: i8) -> Result<(), Self::WriteError> { let bytes = [value as u8; 1]; self.write_all(&bytes) } + #[inline] fn write_u16(&mut self, value: u16) -> Result<(), Self::WriteError> { let mut bytes = [0; 2]; NetworkEndian::write_u16(&mut bytes, value); self.write_all(&bytes) } + #[inline] fn write_i16(&mut self, value: i16) -> Result<(), Self::WriteError> { let mut bytes = [0; 2]; NetworkEndian::write_i16(&mut bytes, value); self.write_all(&bytes) } + #[inline] fn write_u32(&mut self, value: u32) -> Result<(), Self::WriteError> { let mut bytes = [0; 4]; NetworkEndian::write_u32(&mut bytes, value); self.write_all(&bytes) } + #[inline] fn write_i32(&mut self, value: i32) -> Result<(), Self::WriteError> { let mut bytes = [0; 4]; NetworkEndian::write_i32(&mut bytes, value); self.write_all(&bytes) } + #[inline] fn write_u64(&mut self, value: u64) -> Result<(), Self::WriteError> { let mut bytes = [0; 8]; NetworkEndian::write_u64(&mut bytes, value); self.write_all(&bytes) } + #[inline] fn write_i64(&mut self, value: i64) -> Result<(), Self::WriteError> { let mut bytes = [0; 8]; NetworkEndian::write_i64(&mut bytes, value); self.write_all(&bytes) } + #[inline] fn write_bool(&mut self, value: bool) -> Result<(), Self::WriteError> { self.write_u8(value as u8) } + #[inline] fn write_bytes(&mut self, value: &[u8]) -> Result<(), Self::WriteError> { self.write_u32(value.len() as u32)?; self.write_all(value) } + #[inline] fn write_string(&mut self, value: &str) -> Result<(), Self::WriteError> { self.write_bytes(value.as_bytes()) }