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:
commit
c3950c84c0
2 changed files with 3 additions and 1 deletions
|
@ -618,6 +618,8 @@ impl String {
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn from_utf16(v: &[u16]) -> Result<String, FromUtf16Error> {
|
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());
|
let mut ret = String::with_capacity(v.len());
|
||||||
for c in decode_utf16(v.iter().cloned()) {
|
for c in decode_utf16(v.iter().cloned()) {
|
||||||
if let Ok(c) = c {
|
if let Ok(c) = c {
|
||||||
|
|
|
@ -86,7 +86,7 @@ impl<T: Encodable> Encodable for VecDeque<T> {
|
||||||
impl<T:Decodable> Decodable for VecDeque<T> {
|
impl<T:Decodable> Decodable for VecDeque<T> {
|
||||||
fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> {
|
fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> {
|
||||||
d.read_seq(|d, len| {
|
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 {
|
for i in 0..len {
|
||||||
deque.push_back(d.read_seq_elt(i, |d| Decodable::decode(d))?);
|
deque.push_back(d.read_seq_elt(i, |d| Decodable::decode(d))?);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue