mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-10 00:00:09 +02:00
implement put_u8 for BytesMut (#101)
This commit is contained in:
committed by
Carl Lerche
parent
1a6901cdcd
commit
4645f6ec4b
@@ -1164,6 +1164,16 @@ impl BufMut for BytesMut {
|
||||
self.advance_mut(len);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_u8(&mut self, n: u8) {
|
||||
self.inner.put_u8(n);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_i8(&mut self, n: i8) {
|
||||
self.put_u8(n as u8);
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoBuf for BytesMut {
|
||||
@@ -1463,6 +1473,25 @@ impl Inner {
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert a byte into the next slot and advance the len by 1.
|
||||
#[inline]
|
||||
fn put_u8(&mut self, n: u8) {
|
||||
if self.is_inline() {
|
||||
let len = self.inline_len();
|
||||
assert!(len < INLINE_CAP);
|
||||
unsafe {
|
||||
*self.inline_ptr().offset(len as isize) = n;
|
||||
}
|
||||
self.set_inline_len(len + 1);
|
||||
} else {
|
||||
assert!(self.len < self.cap);
|
||||
unsafe {
|
||||
*self.ptr.offset(self.len as isize) = n;
|
||||
}
|
||||
self.len += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn len(&self) -> usize {
|
||||
if self.is_inline() {
|
||||
|
||||
Reference in New Issue
Block a user