[other] Minor optimization in times
This commit is contained in:
parent
fd24a8923e
commit
974362c98f
1 changed files with 12 additions and 9 deletions
|
|
@ -511,6 +511,9 @@ template convert(dur: Duration, unit: static[FixedTimeUnit]): int64 =
|
|||
# The correction is required due to how durations are normalized.
|
||||
# For example,` initDuration(nanoseconds = -1)` is stored as
|
||||
# { seconds = -1, nanoseconds = 999999999 }.
|
||||
when unit == Nanoseconds:
|
||||
dur.seconds * 1_000_000_000 + dur.nanosecond
|
||||
else:
|
||||
let correction = dur.seconds < 0 and dur.nanosecond > 0
|
||||
when unit >= Seconds:
|
||||
convert(Seconds, unit, dur.seconds + ord(correction))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue