Skip to content

Commit b3ff911

Browse files
io: use Buf::put_bytes in Repeat read impl (tokio-rs#7055)
1 parent 9d42b97 commit b3ff911

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

tokio/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ tokio-macros = { version = "~2.4.0", path = "../tokio-macros", optional = true }
9191
pin-project-lite = "0.2.11"
9292

9393
# Everything else is optional...
94-
bytes = { version = "1.0.0", optional = true }
94+
bytes = { version = "1.1.0", optional = true }
9595
mio = { version = "1.0.1", optional = true, default-features = false }
9696
parking_lot = { version = "0.12.0", optional = true }
9797

tokio/src/io/util/repeat.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use bytes::BufMut;
2+
13
use crate::io::util::poll_proceed_and_make_progress;
24
use crate::io::{AsyncRead, ReadBuf};
35

@@ -56,10 +58,7 @@ impl AsyncRead for Repeat {
5658
) -> Poll<io::Result<()>> {
5759
ready!(crate::trace::trace_leaf(cx));
5860
ready!(poll_proceed_and_make_progress(cx));
59-
// TODO: could be faster, but should we unsafe it?
60-
while buf.remaining() != 0 {
61-
buf.put_slice(&[self.byte]);
62-
}
61+
buf.put_bytes(self.byte, buf.remaining());
6362
Poll::Ready(Ok(()))
6463
}
6564
}

0 commit comments

Comments
 (0)