The original would first check that there is right amount of numeric
characters and then parsed them using the std::str::parse, which
internally checks the characters again and also checks for -/+ prefix,
which is not necessary in this case.
Since we are already going over the characters, we may as well do the
parsing ourselves. The length of the function is roughly the same and
it is faster:
name simplify-from-str ns/iter reimplement-number ns/iter diff ns/iter diff % speedup
datetime::tests::bench_datetime_from_str 448 365 -83 -18.53% x 1.23
datetime::tests::bench_datetime_parse_from_rfc2822 242 195 -47 -19.42% x 1.24
datetime::tests::bench_datetime_parse_from_rfc3339 234 166 -68 -29.06% x 1.41
Now (assuming clippy is right) all (~100) uses of ` as ` in the code are
actually doing casts that could potentially silently lose data. Woooo?
At least this means that new `as`s can be extra-scrutinized, and we should
probably be adding debug_assert!s for the casts in real code.
also, previously `Numeric::Nanosecond` had a special left-aligned
parsing behavior. this commit replaces that with a newly designated
`Fixed::Nanosecond` which also handles an empty string which is
possible with an integral number of seconds.
this new module encompasses John Nagle's original RFC 2822 and 3337
parsers, updated to fully compatible to the actual standard.
the contributed `parse` module has been merged into it.
also changes the behavior of `Numeric::Nanosecond` (`%f`) to
the left-aligned digits and allows for the wider range of time zone
offsets from -99:59 to +99:59.