Skip to content

Commit 6af9fef

Browse files
authored
Rollup merge of rust-lang#56131 - ljedrz:assorted, r=RalfJung
Assorted tweaks - preallocate `VecDeque` in `Decodable::decode` (as it is done with other collections which can do it) - add a FIXME to `String::from_utf16` r? @RalfJung
2 parents b6b06bf + 591607d commit 6af9fef

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/liballoc/string.rs

+2
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ impl String {
618618
/// ```
619619
#[stable(feature = "rust1", since = "1.0.0")]
620620
pub fn from_utf16(v: &[u16]) -> Result<String, FromUtf16Error> {
621+
// This isn't done via collect::<Result<_, _>>() for performance reasons.
622+
// FIXME: the function can be simplified again when #48994 is closed.
621623
let mut ret = String::with_capacity(v.len());
622624
for c in decode_utf16(v.iter().cloned()) {
623625
if let Ok(c) = c {

src/libserialize/collection_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<T: Encodable> Encodable for VecDeque<T> {
8686
impl<T:Decodable> Decodable for VecDeque<T> {
8787
fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> {
8888
d.read_seq(|d, len| {
89-
let mut deque: VecDeque<T> = VecDeque::new();
89+
let mut deque: VecDeque<T> = VecDeque::with_capacity(len);
9090
for i in 0..len {
9191
deque.push_back(d.read_seq_elt(i, |d| Decodable::decode(d))?);
9292
}

0 commit comments

Comments
 (0)