update to the latest nightly

This commit is contained in:
Erick Tryzelaar 2014-12-01 12:21:18 -08:00
parent 857723dff6
commit 9d55333f06
5 changed files with 60 additions and 58 deletions

View File

@ -9,7 +9,7 @@ extern crate serialize;
extern crate test; extern crate test;
use std::io; use std::io;
use std::io::{MemWriter, ByRefWriter}; use std::io::ByRefWriter;
use test::Bencher; use test::Bencher;
use serde::de; use serde::de;
@ -622,10 +622,10 @@ fn bench_serializer_mem_writer(b: &mut Bencher) {
b.iter(|| { b.iter(|| {
//let _json = json::to_str(&log).unwrap(); //let _json = json::to_str(&log).unwrap();
let wr = MemWriter::with_capacity(1024); let wr = Vec::with_capacity(1024);
let mut serializer = json::Serializer::new(wr); let mut serializer = json::Serializer::new(wr);
log.serialize(&mut serializer).unwrap(); log.serialize(&mut serializer).unwrap();
let _json = serializer.unwrap().unwrap(); let _json = serializer.unwrap();
}); });
} }
@ -838,14 +838,13 @@ fn bench_manual_mem_writer_no_escape(b: &mut Bencher) {
let log = Log::new(); let log = Log::new();
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":1,"http":{"protocol":2,"status":200,"host_status":503,"up_status":520,"method":1,"content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":2},"country":238,"cache_status":3,"server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#; let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":1,"http":{"protocol":2,"status":200,"host_status":503,"up_status":520,"method":1,"content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":2},"country":238,"cache_status":3,"server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
let mut wr = MemWriter::with_capacity(1024); let mut wr = Vec::with_capacity(1024);
manual_no_escape(wr.by_ref(), &log); manual_no_escape(wr.by_ref(), &log);
b.bytes = wr.unwrap().len() as u64; b.bytes = wr.len() as u64;
b.iter(|| { b.iter(|| {
let mut wr = MemWriter::with_capacity(1024); let mut wr = Vec::with_capacity(1024);
manual_no_escape(wr.by_ref(), &log); manual_no_escape(wr.by_ref(), &log);
let _json = wr.unwrap();
//let _json = String::from_utf8(_json).unwrap(); //let _json = String::from_utf8(_json).unwrap();
//assert_eq!(_s, _json.as_slice()); //assert_eq!(_s, _json.as_slice());
@ -857,14 +856,13 @@ fn bench_manual_mem_writer_escape(b: &mut Bencher) {
let log = Log::new(); let log = Log::new();
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":1,"http":{"protocol":2,"status":200,"host_status":503,"up_status":520,"method":1,"content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":2},"country":238,"cache_status":3,"server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#; let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":1,"http":{"protocol":2,"status":200,"host_status":503,"up_status":520,"method":1,"content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":2},"country":238,"cache_status":3,"server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
let mut wr = MemWriter::with_capacity(1024); let mut wr = Vec::with_capacity(1024);
manual_escape(wr.by_ref(), &log); manual_escape(wr.by_ref(), &log);
b.bytes = wr.unwrap().len() as u64; b.bytes = wr.len() as u64;
b.iter(|| { b.iter(|| {
let mut wr = MemWriter::with_capacity(1024); let mut wr = Vec::with_capacity(1024);
manual_escape(wr.by_ref(), &log); manual_escape(wr.by_ref(), &log);
let _json = wr.unwrap();
//let _json = String::from_utf8(_json).unwrap(); //let _json = String::from_utf8(_json).unwrap();
//assert_eq!(_s, _json.as_slice()); //assert_eq!(_s, _json.as_slice());
@ -898,9 +896,9 @@ fn bench_manual_my_mem_writer0_escape(b: &mut Bencher) {
let log = Log::new(); let log = Log::new();
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#; let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
let mut wr = MemWriter::with_capacity(1024); let mut wr = Vec::with_capacity(1024);
manual_escape(wr.by_ref(), &log); manual_escape(wr.by_ref(), &log);
b.bytes = wr.unwrap().len() as u64; b.bytes = wr.len() as u64;
b.iter(|| { b.iter(|| {
let mut wr = MyMemWriter0::with_capacity(1024); let mut wr = MyMemWriter0::with_capacity(1024);
@ -1001,14 +999,13 @@ fn bench_direct_mem_writer(b: &mut Bencher) {
let log = Log::new(); let log = Log::new();
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#; let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
let mut wr = MemWriter::with_capacity(1024); let mut wr = Vec::with_capacity(1024);
direct(wr.by_ref(), &log); direct(wr.by_ref(), &log);
b.bytes = wr.unwrap().len() as u64; b.bytes = wr.len() as u64;
b.iter(|| { b.iter(|| {
let mut wr = MemWriter::with_capacity(1024); let mut wr = Vec::with_capacity(1024);
direct(wr.by_ref(), &log); direct(wr.by_ref(), &log);
let _json = wr.unwrap();
//let _json = String::from_utf8(wr.unwrap()).unwrap(); //let _json = String::from_utf8(wr.unwrap()).unwrap();
/* /*

View File

@ -510,21 +510,23 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
#[inline] #[inline]
fn expect_seq< fn expect_seq<
'a,
T: Deserialize<Self, E>, T: Deserialize<Self, E>,
C: FromIterator<T> C: FromIterator<T>
>(&'a mut self, token: Token) -> Result<C, E> { >(&mut self, token: Token) -> Result<C, E> {
let len = try!(self.expect_seq_start(token)); let len = try!(self.expect_seq_start(token));
let mut err = None;
let mut d: SeqDeserializer<'a, Self, E> = SeqDeserializer { let collection: C = {
let d = SeqDeserializer {
d: self, d: self,
len: len, len: len,
err: None, err: &mut err,
}; };
let collection: C = d.collect(); d.collect()
};
match d.err { match err {
Some(err) => Err(err), Some(err) => Err(err),
None => Ok(collection), None => Ok(collection),
} }
@ -560,22 +562,24 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
#[inline] #[inline]
fn expect_map< fn expect_map<
'a,
K: Deserialize<Self, E>, K: Deserialize<Self, E>,
V: Deserialize<Self, E>, V: Deserialize<Self, E>,
C: FromIterator<(K, V)> C: FromIterator<(K, V)>
>(&'a mut self, token: Token) -> Result<C, E> { >(&mut self, token: Token) -> Result<C, E> {
let len = try!(self.expect_map_start(token)); let len = try!(self.expect_map_start(token));
let mut err = None;
let mut d: MapDeserializer<'a, Self, E> = MapDeserializer { let collection: C = {
let d = MapDeserializer {
d: self, d: self,
len: len, len: len,
err: None, err: &mut err,
}; };
let collection: C = d.collect(); d.collect()
};
match d.err { match err {
Some(err) => Err(err), Some(err) => Err(err),
None => Ok(collection), None => Ok(collection),
} }
@ -584,10 +588,10 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
struct SeqDeserializer<'a, D: 'a, E> { struct SeqDeserializer<'a, D: 'a, E: 'a> {
d: &'a mut D, d: &'a mut D,
len: uint, len: uint,
err: option::Option<E>, err: &'a mut Option<E>,
} }
impl< impl<
@ -599,9 +603,12 @@ impl<
#[inline] #[inline]
fn next(&mut self) -> option::Option<T> { fn next(&mut self) -> option::Option<T> {
match self.d.expect_seq_elt_or_end() { match self.d.expect_seq_elt_or_end() {
Ok(next) => next, Ok(next) => {
self.len -= 1;
next
}
Err(err) => { Err(err) => {
self.err = Some(err); *self.err = Some(err);
None None
} }
} }
@ -615,10 +622,10 @@ impl<
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
struct MapDeserializer<'a, D:'a, E> { struct MapDeserializer<'a, D:'a, E: 'a> {
d: &'a mut D, d: &'a mut D,
len: uint, len: uint,
err: option::Option<E>, err: &'a mut option::Option<E>,
} }
impl< impl<
@ -633,7 +640,7 @@ impl<
match self.d.expect_map_elt_or_end() { match self.d.expect_map_elt_or_end() {
Ok(next) => next, Ok(next) => next,
Err(err) => { Err(err) => {
self.err = Some(err); *self.err = Some(err);
None None
} }
} }

View File

@ -425,7 +425,7 @@ mod tests {
} }
fn test_encode_ok< fn test_encode_ok<
T: PartialEq + Show + ToJson + ser::Serialize<super::Serializer<io::MemWriter>, io::IoError> T: PartialEq + Show + ToJson + ser::Serialize<super::Serializer<Vec<u8>>, io::IoError>
>(errors: &[(T, &str)]) { >(errors: &[(T, &str)]) {
for &(ref value, out) in errors.iter() { for &(ref value, out) in errors.iter() {
let out = out.to_string(); let out = out.to_string();
@ -439,7 +439,7 @@ mod tests {
} }
fn test_pretty_encode_ok< fn test_pretty_encode_ok<
T: PartialEq + Show + ToJson + ser::Serialize<super::PrettySerializer<io::MemWriter>, io::IoError> T: PartialEq + Show + ToJson + ser::Serialize<super::PrettySerializer<Vec<u8>>, io::IoError>
>(errors: &[(T, &str)]) { >(errors: &[(T, &str)]) {
for &(ref value, out) in errors.iter() { for &(ref value, out) in errors.iter() {
let out = out.to_string(); let out = out.to_string();
@ -1370,7 +1370,6 @@ mod tests {
#[test] #[test]
fn test_encode_hashmap_with_numeric_key() { fn test_encode_hashmap_with_numeric_key() {
use std::str::from_utf8; use std::str::from_utf8;
use std::io::MemWriter;
use std::collections::HashMap; use std::collections::HashMap;
let mut hm: HashMap<uint, bool> = HashMap::new(); let mut hm: HashMap<uint, bool> = HashMap::new();
hm.insert(1, true); hm.insert(1, true);
@ -1386,7 +1385,6 @@ mod tests {
#[test] #[test]
fn test_prettyencode_hashmap_with_numeric_key() { fn test_prettyencode_hashmap_with_numeric_key() {
use std::str::from_utf8; use std::str::from_utf8;
use std::io::MemWriter;
use std::collections::HashMap; use std::collections::HashMap;
let mut hm: HashMap<uint, bool> = HashMap::new(); let mut hm: HashMap<uint, bool> = HashMap::new();
hm.insert(1, true); hm.insert(1, true);

View File

@ -1,7 +1,7 @@
use std::f32; use std::f32;
use std::f64; use std::f64;
use std::num::{Float, FPNaN, FPInfinite}; use std::num::{Float, FPNaN, FPInfinite};
use std::io::{IoError, IoResult, MemWriter}; use std::io::{IoError, IoResult};
use ser::Serialize; use ser::Serialize;
use ser; use ser;
@ -587,18 +587,18 @@ pub fn to_writer<
/// Encode the specified struct into a json `[u8]` buffer. /// Encode the specified struct into a json `[u8]` buffer.
#[inline] #[inline]
pub fn to_vec< pub fn to_vec<
T: Serialize<Serializer<MemWriter>, IoError> T: Serialize<Serializer<Vec<u8>>, IoError>
>(value: &T) -> Vec<u8> { >(value: &T) -> Vec<u8> {
// We are writing to a Vec, which doesn't fail. So we can ignore // We are writing to a Vec, which doesn't fail. So we can ignore
// the error. // the error.
let writer = MemWriter::with_capacity(128); let writer = Vec::with_capacity(128);
to_writer(writer, value).unwrap().unwrap() to_writer(writer, value).unwrap()
} }
/// Encode the specified struct into a json `String` buffer. /// Encode the specified struct into a json `String` buffer.
#[inline] #[inline]
pub fn to_string< pub fn to_string<
T: Serialize<Serializer<MemWriter>, IoError> T: Serialize<Serializer<Vec<u8>>, IoError>
>(value: &T) -> Result<String, Vec<u8>> { >(value: &T) -> Result<String, Vec<u8>> {
let buf = to_vec(value); let buf = to_vec(value);
String::from_utf8(buf) String::from_utf8(buf)
@ -617,17 +617,17 @@ pub fn to_pretty_writer<
/// Encode the specified struct into a json `[u8]` buffer. /// Encode the specified struct into a json `[u8]` buffer.
pub fn to_pretty_vec< pub fn to_pretty_vec<
T: Serialize<PrettySerializer<MemWriter>, IoError> T: Serialize<PrettySerializer<Vec<u8>>, IoError>
>(value: &T) -> Vec<u8> { >(value: &T) -> Vec<u8> {
// We are writing to a Vec, which doesn't fail. So we can ignore // We are writing to a Vec, which doesn't fail. So we can ignore
// the error. // the error.
let writer = MemWriter::with_capacity(128); let writer = Vec::with_capacity(128);
to_pretty_writer(writer, value).unwrap().unwrap() to_pretty_writer(writer, value).unwrap()
} }
/// Encode the specified struct into a json `String` buffer. /// Encode the specified struct into a json `String` buffer.
pub fn to_pretty_string< pub fn to_pretty_string<
T: Serialize<PrettySerializer<MemWriter>, IoError> T: Serialize<PrettySerializer<Vec<u8>>, IoError>
>(value: &T) -> Result<String, Vec<u8>> { >(value: &T) -> Result<String, Vec<u8>> {
let buf = to_pretty_vec(value); let buf = to_pretty_vec(value);
String::from_utf8(buf) String::from_utf8(buf)

View File

@ -1,6 +1,6 @@
use std::collections::{HashMap, TreeMap, tree_map}; use std::collections::{HashMap, TreeMap, tree_map};
use std::fmt; use std::fmt;
use std::io::{ByRefWriter, IoResult, MemWriter}; use std::io::{ByRefWriter, IoResult};
use std::io; use std::io;
use std::str; use std::str;
use std::string; use std::string;
@ -41,9 +41,9 @@ impl Value {
/// Serializes a json value into a string /// Serializes a json value into a string
pub fn to_pretty_string(&self) -> string::String { pub fn to_pretty_string(&self) -> string::String {
let mut wr = MemWriter::new(); let mut wr = Vec::new();
self.to_pretty_writer(wr.by_ref()).unwrap(); self.to_pretty_writer(wr.by_ref()).unwrap();
str::from_utf8(wr.unwrap().as_slice()).unwrap().to_string() str::from_utf8(wr.as_slice()).unwrap().to_string()
} }
/// If the Json value is an Object, returns the value associated with the provided key. /// If the Json value is an Object, returns the value associated with the provided key.