diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 5b10686..7d46297 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -17,7 +17,9 @@ pub enum BufImpl { } macro_rules! forward_method { - (pub fn $fnname:ident(&self $($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*) => { + ($(#[$m:meta])* + pub fn $fnname:ident(&self $($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*) => { + $(#[$m])* pub fn $fnname(&self $($args)*) $(-> $ret)* { match *self { BufImpl::Std(ref buf) => buf.$fnname($($passargs)*), @@ -27,7 +29,9 @@ macro_rules! forward_method { } }; - (pub fn $fnname:ident(&mut self $($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*) => { + ($(#[$m:meta])* + pub fn $fnname:ident(&mut self $($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*) => { + $(#[$m])* pub fn $fnname(&mut self $($args)*) $(-> $ret)* { match *self { BufImpl::Std(ref mut buf) => buf.$fnname($($passargs)*), @@ -37,7 +41,9 @@ macro_rules! forward_method { } }; - (pub unsafe fn $fnname:ident(&self $($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*) => { + ($(#[$m:meta])* + pub unsafe fn $fnname:ident(&self $($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*) => { + $(#[$m])* pub unsafe fn $fnname(&self $($args)*) $(-> $ret)* { match *self { BufImpl::Std(ref buf) => buf.$fnname($($passargs)*), @@ -47,7 +53,9 @@ macro_rules! forward_method { } }; - (pub unsafe fn $fnname:ident(&mut self $($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*) => { + ($(#[$m:meta])* + pub unsafe fn $fnname:ident(&mut self $($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*) => { + $(#[$m])* pub unsafe fn $fnname(&mut self $($args)*) $(-> $ret)* { match *self { BufImpl::Std(ref mut buf) => buf.$fnname($($passargs)*), @@ -59,9 +67,10 @@ macro_rules! forward_method { } macro_rules! forward_methods { - ($($($qualifiers:ident)+ ($($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*);+;) => ( + ($($(#[$m:meta])* + $($qualifiers:ident)+ ($($args:tt)*) [$($passargs:tt)*] $(-> $ret:ty)*);+;) => ( $(forward_method! { - $($qualifiers)+ ($($args)*) [$($passargs)*] $(-> $ret)* + $(#[$m])* $($qualifiers)+ ($($args)*) [$($passargs)*] $(-> $ret)* })* ) } @@ -95,6 +104,7 @@ impl BufImpl { pub fn make_room(&mut self)[]; + #[inline] pub fn buf(&self)[] -> &[u8]; pub fn buf_mut(&mut self)[] -> &mut [u8]; diff --git a/src/buffer/slice_deque_buf.rs b/src/buffer/slice_deque_buf.rs index f5dee48..91bcfec 100644 --- a/src/buffer/slice_deque_buf.rs +++ b/src/buffer/slice_deque_buf.rs @@ -46,6 +46,7 @@ impl SliceDequeBuf { /// This method is a no-op. pub fn make_room(&mut self) {} + #[inline] pub fn buf(&self) -> &[u8] { &self.deque } diff --git a/src/buffer/std_buf.rs b/src/buffer/std_buf.rs index 1594737..7bf89c3 100644 --- a/src/buffer/std_buf.rs +++ b/src/buffer/std_buf.rs @@ -73,6 +73,7 @@ impl StdBuf { self.end = len; } + #[inline] pub fn buf(&self) -> &[u8] { unsafe { &self.buf.as_slice()[self.pos..self.end] } } @@ -152,6 +153,7 @@ mod impl_ { false } + #[inline] pub unsafe fn as_slice(&self) -> &[u8] { &self.buf } diff --git a/src/lib.rs b/src/lib.rs index 48875d1..bbd3659 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -285,6 +285,7 @@ impl BufReader { /// Get the section of the buffer containing valid data; may be empty. /// /// Call `.consume()` to remove bytes from the beginning of this section. + #[inline] pub fn buffer(&self) -> &[u8] { self.buf.buf() } @@ -1011,6 +1012,7 @@ impl Buffer { /// Get an immutable slice of the available bytes in this buffer. /// /// Call `.consume()` to remove bytes from the beginning of this slice. + #[inline] pub fn buf(&self) -> &[u8] { self.buf.buf() } @@ -1215,6 +1217,7 @@ impl Unbuffer { } /// Get a slice over the available bytes in the buffer. + #[inline] pub fn buf(&self) -> &[u8] { self.buf.as_ref().map_or(&[], Buffer::buf) }