Get the benchmark running again
This commit is contained in:
parent
f7eb082339
commit
e2568ddfac
@ -67,7 +67,7 @@ impl de::Deserialize for HttpField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
//#[derive_serialize]
|
#[derive_serialize]
|
||||||
//#[derive_deserialize]
|
//#[derive_deserialize]
|
||||||
struct Http {
|
struct Http {
|
||||||
protocol: HttpProtocol,
|
protocol: HttpProtocol,
|
||||||
@ -299,7 +299,7 @@ impl de::Deserialize for OriginField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
//#[derive_serialize]
|
#[derive_serialize]
|
||||||
//#[derive_deserialize]
|
//#[derive_deserialize]
|
||||||
struct Origin {
|
struct Origin {
|
||||||
ip: String,
|
ip: String,
|
||||||
@ -773,7 +773,7 @@ impl de::Deserialize for LogField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
//#[derive_serialize]
|
#[derive_serialize]
|
||||||
//#[derive_deserialize]
|
//#[derive_deserialize]
|
||||||
struct Log {
|
struct Log {
|
||||||
timestamp: i64,
|
timestamp: i64,
|
||||||
@ -887,7 +887,6 @@ impl Log {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
macro_rules! likely(
|
macro_rules! likely(
|
||||||
($val:expr) => {
|
($val:expr) => {
|
||||||
{
|
{
|
||||||
@ -1477,4 +1476,3 @@ fn bench_deserializer(b: &mut Bencher) {
|
|||||||
let _log: Log = json::from_str(JSON_STR).unwrap();
|
let _log: Log = json::from_str(JSON_STR).unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
@ -79,34 +79,14 @@ fn expand_derive_serialize<>(cx: &mut ExtCtxt,
|
|||||||
generics: LifetimeBounds {
|
generics: LifetimeBounds {
|
||||||
lifetimes: Vec::new(),
|
lifetimes: Vec::new(),
|
||||||
bounds: vec![
|
bounds: vec![
|
||||||
("__S", vec![]),
|
("__V", vec![Path::new(vec!["serde2", "ser", "Visitor"])]),
|
||||||
("__R", vec![]),
|
|
||||||
("__E", vec![]),
|
|
||||||
(
|
|
||||||
"__V",
|
|
||||||
vec![
|
|
||||||
Path::new_(
|
|
||||||
vec!["serde2", "ser", "Visitor"],
|
|
||||||
None,
|
|
||||||
vec![
|
|
||||||
Box::new(Literal(Path::new_local("__S"))),
|
|
||||||
Box::new(Literal(Path::new_local("__R"))),
|
|
||||||
Box::new(Literal(Path::new_local("__E"))),
|
|
||||||
],
|
|
||||||
true
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: vec![
|
args: vec![
|
||||||
Ptr(
|
Ptr(
|
||||||
Box::new(Literal(Path::new_local("__S"))),
|
Box::new(Literal(Path::new_local("__V"))),
|
||||||
Borrowed(None, MutMutable)
|
Borrowed(None, MutMutable),
|
||||||
),
|
|
||||||
Literal(
|
|
||||||
Path::new_local("__V"),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
ret_ty: Literal(
|
ret_ty: Literal(
|
||||||
@ -114,8 +94,14 @@ fn expand_derive_serialize<>(cx: &mut ExtCtxt,
|
|||||||
vec!("std", "result", "Result"),
|
vec!("std", "result", "Result"),
|
||||||
None,
|
None,
|
||||||
vec![
|
vec![
|
||||||
Box::new(Literal(Path::new_local("__R"))),
|
Box::new(Literal(Path::new_(vec!["__V", "Value"],
|
||||||
Box::new(Literal(Path::new_local("__E"))),
|
None,
|
||||||
|
vec![],
|
||||||
|
false))),
|
||||||
|
Box::new(Literal(Path::new_(vec!["__V", "Error"],
|
||||||
|
None,
|
||||||
|
vec![],
|
||||||
|
false))),
|
||||||
],
|
],
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
@ -132,20 +118,19 @@ fn expand_derive_serialize<>(cx: &mut ExtCtxt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
|
fn serialize_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
|
||||||
let state = substr.nonself_args[0].clone();
|
let visitor = substr.nonself_args[0].clone();
|
||||||
let visitor = substr.nonself_args[1].clone();
|
|
||||||
|
|
||||||
match *substr.fields {
|
match *substr.fields {
|
||||||
Struct(ref fields) => {
|
Struct(ref fields) => {
|
||||||
if fields.is_empty() {
|
if fields.is_empty() {
|
||||||
serialize_tuple_struct(cx)
|
serialize_tuple_struct(cx)
|
||||||
} else {
|
} else {
|
||||||
serialize_struct(cx, span, state, visitor, substr.type_ident, fields)
|
serialize_struct(cx, span, visitor, substr.type_ident, fields)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnumMatching(_idx, variant, ref fields) => {
|
EnumMatching(_idx, variant, ref fields) => {
|
||||||
serialize_enum(cx, span, state, visitor, substr.type_ident, variant, fields)
|
serialize_enum(cx, span, visitor, substr.type_ident, variant, fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => cx.bug("expected Struct or EnumMatching in derive_serialize")
|
_ => cx.bug("expected Struct or EnumMatching in derive_serialize")
|
||||||
@ -159,7 +144,6 @@ fn serialize_tuple_struct(cx: &ExtCtxt) -> P<Expr> {
|
|||||||
|
|
||||||
fn serialize_struct(cx: &ExtCtxt,
|
fn serialize_struct(cx: &ExtCtxt,
|
||||||
span: Span,
|
span: Span,
|
||||||
state: P<Expr>,
|
|
||||||
visitor: P<Expr>,
|
visitor: P<Expr>,
|
||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
fields: &Vec<FieldInfo>) -> P<Expr> {
|
fields: &Vec<FieldInfo>) -> P<Expr> {
|
||||||
@ -181,10 +165,12 @@ fn serialize_struct(cx: &ExtCtxt,
|
|||||||
let name = name.unwrap();
|
let name = name.unwrap();
|
||||||
let expr = cx.expr_str(span, token::get_ident(name));
|
let expr = cx.expr_str(span, token::get_ident(name));
|
||||||
|
|
||||||
|
let i = i as u32;
|
||||||
|
|
||||||
quote_arm!(cx,
|
quote_arm!(cx,
|
||||||
$i => {
|
$i => {
|
||||||
self.state += 1;
|
self.state += 1;
|
||||||
let v = try!(visitor.visit_map_elt(state, $first, $expr, &self.value.$name));
|
let v = try!(visitor.visit_map_elt($first, $expr, &self.value.$name));
|
||||||
Ok(Some(v))
|
Ok(Some(v))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -193,20 +179,15 @@ fn serialize_struct(cx: &ExtCtxt,
|
|||||||
|
|
||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
struct Visitor<'a> {
|
struct Visitor<'a> {
|
||||||
state: uint,
|
state: u32,
|
||||||
value: &'a $type_ident,
|
value: &'a $type_ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<'a> ::serde2::ser::MapVisitor for Visitor<'a> {
|
||||||
'a,
|
|
||||||
S,
|
|
||||||
R,
|
|
||||||
E,
|
|
||||||
> ::serde2::ser::MapVisitor<S, R, E> for Visitor<'a> {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit<
|
fn visit<
|
||||||
V: ::serde2::ser::Visitor<S, R, E>,
|
V: ::serde2::ser::Visitor,
|
||||||
>(&mut self, state: &mut S, visitor: V) -> Result<Option<R>, E> {
|
>(&mut self, visitor: &mut V) -> Result<Option<V::Value>, V::Error> {
|
||||||
match self.state {
|
match self.state {
|
||||||
$arms
|
$arms
|
||||||
_ => Ok(None),
|
_ => Ok(None),
|
||||||
@ -214,13 +195,13 @@ fn serialize_struct(cx: &ExtCtxt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn size_hint(&self) -> (uint, Option<uint>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
let size = $len - self.state;
|
let size = $len - (self.state as usize);
|
||||||
(size, Some(size))
|
(size, Some(size))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$visitor.visit_named_map($state, $type_name, Visitor {
|
$visitor.visit_named_map($type_name, Visitor {
|
||||||
value: self,
|
value: self,
|
||||||
state: 0,
|
state: 0,
|
||||||
})
|
})
|
||||||
@ -229,7 +210,6 @@ fn serialize_struct(cx: &ExtCtxt,
|
|||||||
|
|
||||||
fn serialize_enum(cx: &ExtCtxt,
|
fn serialize_enum(cx: &ExtCtxt,
|
||||||
span: Span,
|
span: Span,
|
||||||
state: P<Expr>,
|
|
||||||
visitor: P<Expr>,
|
visitor: P<Expr>,
|
||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
variant: &ast::Variant,
|
variant: &ast::Variant,
|
||||||
@ -248,15 +228,15 @@ fn serialize_enum(cx: &ExtCtxt,
|
|||||||
.map(|&FieldInfo { ref self_, .. }| {
|
.map(|&FieldInfo { ref self_, .. }| {
|
||||||
quote_stmt!(
|
quote_stmt!(
|
||||||
cx,
|
cx,
|
||||||
try!($visitor.serialize_enum_elt($state, &$self_))
|
try!($visitor.serialize_enum_elt(&$self_))
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
try!($visitor.serialize_enum_start($state, $type_name, $variant_name, $len));
|
try!($visitor.serialize_enum_start($type_name, $variant_name, $len));
|
||||||
$stmts
|
$stmts
|
||||||
$visitor.serialize_enum_end($state)
|
$visitor.serialize_enum_end()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,7 +533,7 @@ fn deserialize_enum(
|
|||||||
|
|
||||||
/// Create a deserializer for a single enum variant/struct:
|
/// Create a deserializer for a single enum variant/struct:
|
||||||
/// - `outer_pat_ident` is the name of this enum variant/struct
|
/// - `outer_pat_ident` is the name of this enum variant/struct
|
||||||
/// - `getarg` should retrieve the `uint`-th field with name `&str`.
|
/// - `getarg` should retrieve the `u32`-th field with name `&str`.
|
||||||
fn deserialize_static_fields(
|
fn deserialize_static_fields(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user