From 5fbcbdd5f7f3be9d3340e22576b723b44611147b Mon Sep 17 00:00:00 2001 From: Edward Barnard Date: Sat, 29 Aug 2015 12:48:57 +0700 Subject: Switch to using BTreeMap for dictionaries --- src/builder.rs | 13 +++++-------- src/lib.rs | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/builder.rs b/src/builder.rs index 50afad7..d1eec78 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::BTreeMap; use std::io::{Read, Seek}; use {ParserError, ParserResult, Plist, PlistEvent, StreamingParser}; @@ -102,11 +102,8 @@ impl>> Builder { } } - fn build_dict(&mut self, len: Option) -> Result, BuilderError> { - let mut values = match len { - Some(len) => HashMap::with_capacity(len as usize), - None => HashMap::new() - }; + fn build_dict(&mut self, len: Option) -> Result, BuilderError> { + let mut values = BTreeMap::new(); loop { try!(self.bump()); @@ -127,7 +124,7 @@ impl>> Builder { #[cfg(test)] mod tests { - use std::collections::HashMap; + use std::collections::BTreeMap; use super::*; use Plist; @@ -165,7 +162,7 @@ mod tests { lines.push(Plist::String("It is a tale told by an idiot,".to_owned())); lines.push(Plist::String("Full of sound and fury, signifying nothing.".to_owned())); - let mut dict = HashMap::new(); + let mut dict = BTreeMap::new(); dict.insert("Author".to_owned(), Plist::String("William Shakespeare".to_owned())); dict.insert("Lines".to_owned(), Plist::Array(lines)); dict.insert("Birthdate".to_owned(), Plist::Integer(1564)); diff --git a/src/lib.rs b/src/lib.rs index 30d19dd..38e348c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,14 +12,14 @@ pub use builder::{Builder, BuilderError, BuilderResult}; use chrono::{DateTime, UTC}; use chrono::format::ParseError as ChronoParseError; -use std::collections::HashMap; +use std::collections::BTreeMap; use std::io::{Read, Seek, SeekFrom}; use std::io::Error as IoError; #[derive(Clone, Debug, PartialEq)] pub enum Plist { Array(Vec), - Dictionary(HashMap), + Dictionary(BTreeMap), Boolean(bool), Data(Vec), Date(DateTime), -- cgit v1.2.3