perf(h1): remove book keeping on final body writes
This commit is contained in:
34
src/common/buf.rs
Normal file
34
src/common/buf.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use bytes::Buf;
|
||||
use iovec::IoVec;
|
||||
|
||||
/// A `Buf` wrapping a static byte slice.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct StaticBuf(pub(crate) &'static [u8]);
|
||||
|
||||
impl Buf for StaticBuf {
|
||||
#[inline]
|
||||
fn remaining(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bytes(&self) -> &[u8] {
|
||||
self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn advance(&mut self, cnt: usize) {
|
||||
self.0 = &self.0[cnt..];
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bytes_vec<'t>(&'t self, dst: &mut [&'t IoVec]) -> usize {
|
||||
if dst.is_empty() {
|
||||
return 0;
|
||||
} else {
|
||||
dst[0] = self.0.into();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user