perf(http): introduce MemBuf, a shared read buffer

This commit is contained in:
Sean McArthur
2017-01-07 09:08:17 -08:00
parent 2d2d5574a6
commit be461b4663
13 changed files with 473 additions and 456 deletions

View File

@@ -52,18 +52,6 @@ impl Read for Buf {
}
}
impl ::vecio::Writev for Buf {
fn writev(&mut self, bufs: &[&[u8]]) -> io::Result<usize> {
let cap = bufs.iter().map(|buf| buf.len()).fold(0, |total, next| total + next);
let mut vec = Vec::with_capacity(cap);
for &buf in bufs {
vec.extend(buf);
}
self.write(&vec)
}
}
#[derive(Debug)]
pub struct AsyncIo<T> {
inner: T,
@@ -147,18 +135,6 @@ impl<T: Read + Write> Io for AsyncIo<T> {
}
}
impl<T: Write> ::vecio::Writev for AsyncIo<T> {
fn writev(&mut self, bufs: &[&[u8]]) -> io::Result<usize> {
let cap = bufs.iter().map(|buf| buf.len()).fold(0, |total, next| total + next);
let mut vec = Vec::with_capacity(cap);
for &buf in bufs {
vec.extend(buf);
}
self.write(&vec)
}
}
impl ::std::ops::Deref for AsyncIo<Buf> {
type Target = [u8];