1
Fork 0

Rollup merge of #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
This commit is contained in:
kennytm 2018-12-01 01:05:51 +08:00 committed by GitHub
commit c3950c84c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -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 {

View file

@ -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))?);
}