This is a way to avoid instantiating all the Visitor methods on every
Visitor that is used with serde_json. If the Deserialize impl hints
that a boolean is required by invoking deserialize_bool, we don't also
need to instantiate its visit_u64 and visit_i64 and visit_f64 and
visit_str and visit_borrowed_str and visit_unit and visit_seq and
visit_map methods if the input contains some other type. Instead we
render the invalid_type error in a central place in the serde_json
Deserializer that is instantiated just once.
Improves compile time of json-benchmark by 30%.
The parse_value method is the most expensive method in serde_json in
terms of compile time. Before this change, we were instantiating it
twice for every derive(Deserialize) struct because every struct has
two different Visitor impls -- one for the key type and one for the
struct overall -- see https://serde.rs/deserialize-struct.html.
This improves compile time of json-benchmark by 20%.
This code catches things like `[1, 2], 3` where the `, 3` are trailing
characters but the comma is not a trailing comma. Trailing comma is like
the commas in `[1,]` or `{"f":2,}`.
Now that Rust 1.18 has come out, and according to our policy of supporting
the past 3 versions of rust, we can finally switch to using
`char::encode_utf8` to encode a character into a string.
Closes#270.
All these functions end up calling visit_f64 so rewriting these
functions to avoid dependence on the visitor type V is a no-brainer:
- parse_long_integer
- parse_decimal
- parse_exponent
- parse_exponent_overflow
- visit_f64_from_parts