mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-07 00:00:13 +02:00
Remove redundant reserve call (#674)
This commit is contained in:
@@ -1283,9 +1283,7 @@ impl Extend<u8> for BytesMut {
|
|||||||
|
|
||||||
// TODO: optimize
|
// TODO: optimize
|
||||||
// 1. If self.kind() == KIND_VEC, use Vec::extend
|
// 1. If self.kind() == KIND_VEC, use Vec::extend
|
||||||
// 2. Make `reserve` inline-able
|
|
||||||
for b in iter {
|
for b in iter {
|
||||||
self.reserve(1);
|
|
||||||
self.put_u8(b);
|
self.put_u8(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -598,6 +598,28 @@ fn extend_mut_from_bytes() {
|
|||||||
assert_eq!(*bytes, LONG[..]);
|
assert_eq!(*bytes, LONG[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extend_past_lower_limit_of_size_hint() {
|
||||||
|
// See https://github.com/tokio-rs/bytes/pull/674#pullrequestreview-1913035700
|
||||||
|
struct Iter<I>(I);
|
||||||
|
|
||||||
|
impl<I: Iterator<Item = u8>> Iterator for Iter<I> {
|
||||||
|
type Item = u8;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
self.0.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
(5, None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut bytes = BytesMut::with_capacity(5);
|
||||||
|
bytes.extend(Iter(std::iter::repeat(0).take(10)));
|
||||||
|
assert_eq!(bytes.len(), 10);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn extend_mut_without_size_hint() {
|
fn extend_mut_without_size_hint() {
|
||||||
let mut bytes = BytesMut::with_capacity(0);
|
let mut bytes = BytesMut::with_capacity(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user