From 464c9da9c229111298d413882735ea707a30e077 Mon Sep 17 00:00:00 2001 From: ljedrz <ljedrz@gmail.com> Date: Wed, 21 Nov 2018 10:07:33 +0100 Subject: [PATCH 1/2] serialize: preallocate VecDeque in Decodable::decode --- src/libserialize/collection_impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index 3e028d755c6d4..cbd642dd6ad91 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -86,7 +86,7 @@ impl<T: Encodable> Encodable for VecDeque<T> { impl<T:Decodable> Decodable for VecDeque<T> { fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> { d.read_seq(|d, len| { - let mut deque: VecDeque<T> = VecDeque::new(); + let mut deque: VecDeque<T> = VecDeque::with_capacity(len); for i in 0..len { deque.push_back(d.read_seq_elt(i, |d| Decodable::decode(d))?); } From 591607d237665857880e16899788517b9b82d414 Mon Sep 17 00:00:00 2001 From: ljedrz <ljedrz@gmail.com> Date: Wed, 21 Nov 2018 10:17:54 +0100 Subject: [PATCH 2/2] String: add a FIXME to from_utf16 --- src/liballoc/string.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 8d009101ce7da..0b25d911a299c 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -618,6 +618,8 @@ impl String { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn from_utf16(v: &[u16]) -> Result<String, FromUtf16Error> { + // This isn't done via collect::<Result<_, _>>() for performance reasons. + // FIXME: the function can be simplified again when #48994 is closed. let mut ret = String::with_capacity(v.len()); for c in decode_utf16(v.iter().cloned()) { if let Ok(c) = c {