Replace TreeMap with BTreeMap in the serde2

This commit is contained in:
Thomas Bahn 2014-12-23 18:33:37 +01:00
parent 7fa62b6212
commit 512a54e983
6 changed files with 27 additions and 27 deletions

View File

@ -253,7 +253,7 @@ impl<
///////////////////////////////////////////////////////////////////////////////
mod json {
use std::collections::TreeMap;
use std::collections::BTreeMap;
use serde2::de;
#[deriving(Show)]
@ -263,7 +263,7 @@ mod json {
Int(int),
//String(String),
List(Vec<Value>),
Map(TreeMap<String, Value>),
Map(BTreeMap<String, Value>),
}
impl<
@ -323,7 +323,7 @@ mod json {
fn visit_map<
Visitor: de::MapVisitor<D, E>,
>(&mut self, mut visitor: Visitor) -> Result<Value, E> {
let mut values = TreeMap::new();
let mut values = BTreeMap::new();
loop {
match try!(visitor.visit()) {
@ -500,7 +500,7 @@ pub fn main() {
/*
use std::collections::TreeMap;
use std::collections::BTreeMap;
use serde::{Serialize, GatherTokens};
use serde::json;
@ -578,7 +578,7 @@ fn main() {
////
let mut value = TreeMap::new();
let mut value = BTreeMap::new();
value.insert("a", 1i);
value.insert("b", 2);
value.insert("c", 3);

View File

@ -1,4 +1,4 @@
use std::collections::{HashMap, TreeMap};
use std::collections::{HashMap, BTreeMap};
use std::hash::Hash;
///////////////////////////////////////////////////////////////////////////////
@ -472,8 +472,8 @@ impl<
V: Deserialize<S, E>,
S: Deserializer<E>,
E: Error,
> Deserialize<S, E> for TreeMap<K, V> {
fn deserialize(state: &mut S) -> Result<TreeMap<K, V>, E> {
> Deserialize<S, E> for BTreeMap<K, V> {
fn deserialize(state: &mut S) -> Result<BTreeMap<K, V>, E> {
struct Visitor;
impl<
@ -481,11 +481,11 @@ impl<
V: Deserialize<S, E>,
S: Deserializer<E>,
E: Error,
> self::Visitor<S, TreeMap<K, V>, E> for Visitor {
> self::Visitor<S, BTreeMap<K, V>, E> for Visitor {
fn visit_map<
Visitor: MapVisitor<S, E>,
>(&mut self, mut visitor: Visitor) -> Result<TreeMap<K, V>, E> {
let mut values = TreeMap::new();
>(&mut self, mut visitor: Visitor) -> Result<BTreeMap<K, V>, E> {
let mut values = BTreeMap::new();
loop {
match try!(visitor.visit()) {

View File

@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::collections::TreeMap;
use std::str::StrAllocating;
use std::collections::BTreeMap;
use ser::{mod, Serialize};
use json::value::{mod, Value};
@ -46,12 +46,12 @@ impl ArrayBuilder {
}
pub struct ObjectBuilder {
object: TreeMap<String, Value>,
object: BTreeMap<String, Value>,
}
impl ObjectBuilder {
pub fn new() -> ObjectBuilder {
ObjectBuilder { object: TreeMap::new() }
ObjectBuilder { object: BTreeMap::new() }
}
pub fn unwrap(self) -> Value {
@ -78,7 +78,7 @@ impl ObjectBuilder {
#[cfg(test)]
mod tests {
use std::collections::TreeMap;
use std::collections::BTreeMap;
use json::value::Value;
use super::{ArrayBuilder, ObjectBuilder};
@ -107,7 +107,7 @@ mod tests {
.insert("b".to_string(), 2i))
.unwrap();
let mut map = TreeMap::new();
let mut map = BTreeMap::new();
map.insert("a".to_string(), Value::I64(1));
map.insert("b".to_string(), Value::I64(2));
assert_eq!(value, Value::Array(vec!(Value::Object(map))));
@ -116,14 +116,14 @@ mod tests {
#[test]
fn test_object_builder() {
let value = ObjectBuilder::new().unwrap();
assert_eq!(value, Value::Object(TreeMap::new()));
assert_eq!(value, Value::Object(BTreeMap::new()));
let value = ObjectBuilder::new()
.insert("a".to_string(), 1i)
.insert("b".to_string(), 2i)
.unwrap();
let mut map = TreeMap::new();
let mut map = BTreeMap::new();
map.insert("a".to_string(), Value::I64(1));
map.insert("b".to_string(), Value::I64(2));
assert_eq!(value, Value::Object(map));

View File

@ -529,7 +529,7 @@ pub fn from_str<
mod tests {
use std::str;
use std::fmt::Show;
use std::collections::TreeMap;
use std::collections::BTreeMap;
use de::Deserialize;
use super::{Parser, from_str};
@ -537,7 +537,7 @@ mod tests {
macro_rules! treemap {
($($k:expr => $v:expr),*) => ({
let mut _m = TreeMap::new();
let mut _m = BTreeMap::new();
$(_m.insert($k, $v);)*
_m
})
@ -694,7 +694,7 @@ mod tests {
#[test]
fn test_parse_object() {
test_parse_err::<TreeMap<String, int>>(vec![
test_parse_err::<BTreeMap<String, int>>(vec![
("{", Error::SyntaxError(ErrorCode::EOFWhileParsingValue, 1, 2)),
("{ ", Error::SyntaxError(ErrorCode::EOFWhileParsingValue, 1, 3)),
("{1", Error::SyntaxError(ErrorCode::KeyMustBeAString, 1, 2)),

View File

@ -1,4 +1,4 @@
use std::collections::TreeMap;
use std::collections::BTreeMap;
use std::fmt;
use std::io;
@ -12,7 +12,7 @@ pub enum Value {
F64(f64),
String(String),
Array(Vec<Value>),
Object(TreeMap<String, Value>),
Object(BTreeMap<String, Value>),
}
impl ser::Serialize for Value {
@ -77,7 +77,7 @@ pub fn to_value<
enum State {
Value(Value),
Array(Vec<Value>),
Object(TreeMap<String, Value>),
Object(BTreeMap<String, Value>),
}
pub struct Writer {
@ -203,7 +203,7 @@ impl ser::Visitor<Writer, (), ()> for Visitor {
fn visit_map<
V: ser::MapVisitor<Writer, (), ()>
>(&self, state: &mut Writer, mut visitor: V) -> Result<(), ()> {
let values = TreeMap::new();
let values = BTreeMap::new();
state.state.push(State::Object(values));

View File

@ -1,4 +1,4 @@
use std::collections::TreeMap;
use std::collections::BTreeMap;
///////////////////////////////////////////////////////////////////////////////
@ -491,7 +491,7 @@ impl<
impl<
K: Serialize + Ord,
V: Serialize,
> Serialize for TreeMap<K, V> {
> Serialize for BTreeMap<K, V> {
#[inline]
fn visit<
S,