Closed
Description
At the moment the Duration
type looks like
pub struct Duraion {
secs: i64,
nanos: i32
}
According to this, one can expect that maximum possible duration value is at least i64::MAX
seconds. But in fact, the full range that i64 seconds gives us is restricted to i64::MAX
milliseconds (see #16626 for more details).
I offer to change the internal representation of Duration
to
pub struct Duraion {
ticks: i64, // A single tick represents 100 nanoseconds
nanos: i8 // to hold values from -99 to 99
}
Some pros:
- Internals of
struct Duraion
are not exposed. So, we are free to change them. - New representation is 3 bytes smaller.
- Methods like
num_milliseconds
etc will return correct i64 values (see libstd: Refactor Duration. #16626). TimeSpan
in .NET andDuration
in Joda-Time types do the same.
Some cons:
- The overall range of values for
Duration
will be shorter:i64::MAX
seconds gives us 106751991167300 days. We don't useneedit.i64::MAX
milliseconds gives us 106751991167 days. This is our current choice.i64::MAX
ticks gives us 10675199 days. The range is still long enough, who cares?
- ?
Metadata
Metadata
Assignees
Labels
No labels