Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Remove calls to <Collection>::with_capacity(). #122

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/collection_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<K, V> Decodable for HashMap<K, V>
{
fn decode<D: Decoder>(d: &mut D) -> Result<HashMap<K, V>, D::Error> {
d.read_map(|d, len| {
let mut map = HashMap::with_capacity(len);
let mut map = HashMap::new();
for i in 0..len {
let key = try!(d.read_map_elt_key(i, |d| Decodable::decode(d)));
let val = try!(d.read_map_elt_val(i, |d| Decodable::decode(d)));
Expand All @@ -176,7 +176,7 @@ impl<T> Encodable for HashSet<T> where T: Encodable + Hash + Eq {
impl<T> Decodable for HashSet<T> where T: Decodable + Hash + Eq, {
fn decode<D: Decoder>(d: &mut D) -> Result<HashSet<T>, D::Error> {
d.read_seq(|d, len| {
let mut set = HashSet::with_capacity(len);
let mut set = HashSet::new();
for i in 0..len {
set.insert(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
}
Expand Down
4 changes: 2 additions & 2 deletions src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl<T:Encodable> Encodable for Vec<T> {
impl<T:Decodable> Decodable for Vec<T> {
fn decode<D: Decoder>(d: &mut D) -> Result<Vec<T>, D::Error> {
d.read_seq(|d, len| {
let mut v = Vec::with_capacity(len);
let mut v = Vec::new();
for i in 0..len {
v.push(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
}
Expand Down Expand Up @@ -722,7 +722,7 @@ impl<D: Decoder> DecoderHelpers for D {
FnMut(&mut D) -> Result<T, D::Error>,
{
self.read_seq(|this, len| {
let mut v = Vec::with_capacity(len);
let mut v = Vec::new();
for i in 0..len {
v.push(try!(this.read_seq_elt(i, |this| f(this))));
}
Expand Down