Skip to content

Commit

Permalink
Rollup merge of rust-lang#56131 - ljedrz:assorted, r=RalfJung
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pietroalbini authored Nov 29, 2018
2 parents 57d184b + 591607d commit bb1e861
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/libserialize/collection_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?);
}
Expand Down

0 comments on commit bb1e861

Please sign in to comment.