VecDeque::read_to_string
: avoid making the slices contiguous
This commit is contained in:
parent
b07c1f7f4d
commit
23211b638a
1 changed files with 2 additions and 9 deletions
|
@ -474,15 +474,8 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
|
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
|
||||||
// We have to use a single contiguous slice because the `VecDequeue` might be split in the
|
// SAFETY: We only append to the buffer
|
||||||
// middle of an UTF-8 character.
|
unsafe { io::append_to_string(buf, |buf| self.read_to_end(buf)) }
|
||||||
let len = self.len();
|
|
||||||
let content = self.make_contiguous();
|
|
||||||
let string = str::from_utf8(content).map_err(|_| io::Error::INVALID_UTF8)?;
|
|
||||||
buf.try_reserve(len)?;
|
|
||||||
buf.push_str(string);
|
|
||||||
self.clear();
|
|
||||||
Ok(len)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue