Add Read/Write::can_read/write_vectored
When working with an arbitrary reader or writer, code that uses vectored
operations may end up being slower than code that copies into a single
buffer when the underlying reader or writer doesn't actually support
vectored operations. These new methods allow you to ask the reader or
witer up front if vectored operations are efficiently supported.
Currently, you have to use some heuristics to guess by e.g. checking if
the read or write only accessed the first buffer. Hyper is one concrete
example of a library that has to do this dynamically:
0eaf304644/src/proto/h1/io.rs (L582-L594)
This commit is contained in:
parent
019ab732ce
commit
15262ec6be
43 changed files with 556 additions and 0 deletions
|
@ -580,6 +580,19 @@ pub trait Read {
|
|||
default_read_vectored(|b| self.read(b), bufs)
|
||||
}
|
||||
|
||||
/// Determines if this `Read`er has an efficient `read_vectored`
|
||||
/// implementation.
|
||||
///
|
||||
/// If a `Read`er does not override the default `read_vectored`
|
||||
/// implementation, code using it may want to avoid the method all together
|
||||
/// and coalesce writes into a single buffer for higher performance.
|
||||
///
|
||||
/// The default implementation returns `false`.
|
||||
#[unstable(feature = "can_vector", issue = "none")]
|
||||
fn can_read_vectored(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Determines if this `Read`er can work with buffers of uninitialized
|
||||
/// memory.
|
||||
///
|
||||
|
@ -1304,6 +1317,19 @@ pub trait Write {
|
|||
default_write_vectored(|b| self.write(b), bufs)
|
||||
}
|
||||
|
||||
/// Determines if this `Write`er has an efficient `write_vectored`
|
||||
/// implementation.
|
||||
///
|
||||
/// If a `Write`er does not override the default `write_vectored`
|
||||
/// implementation, code using it may want to avoid the method all together
|
||||
/// and coalesce writes into a single buffer for higher performance.
|
||||
///
|
||||
/// The default implementation returns `false`.
|
||||
#[unstable(feature = "can_vector", issue = "none")]
|
||||
fn can_write_vectored(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Flush this output stream, ensuring that all intermediately buffered
|
||||
/// contents reach their destination.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue