From 218021732ebf0620c9865f06e408ae0d25390e4b Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sun, 29 Dec 2024 21:51:36 +0100 Subject: [PATCH] io: use `Buf::put_bytes` in `Repeat` read impl --- tokio/src/io/util/repeat.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tokio/src/io/util/repeat.rs b/tokio/src/io/util/repeat.rs index ecdbc7d062c..33a8fd9862b 100644 --- a/tokio/src/io/util/repeat.rs +++ b/tokio/src/io/util/repeat.rs @@ -1,3 +1,5 @@ +use bytes::BufMut; + use crate::io::util::poll_proceed_and_make_progress; use crate::io::{AsyncRead, ReadBuf}; @@ -56,10 +58,7 @@ impl AsyncRead for Repeat { ) -> Poll> { ready!(crate::trace::trace_leaf(cx)); ready!(poll_proceed_and_make_progress(cx)); - // TODO: could be faster, but should we unsafe it? - while buf.remaining() != 0 { - buf.put_slice(&[self.byte]); - } + buf.put_bytes(self.byte, buf.remaining()); Poll::Ready(Ok(())) } }