diff options
-rw-r--r-- | absl/time/duration.cc | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/absl/time/duration.cc b/absl/time/duration.cc index 4c25dc40..8d0b66f8 100644 --- a/absl/time/duration.cc +++ b/absl/time/duration.cc @@ -280,33 +280,35 @@ inline bool IDivFastPath(const Duration num, const Duration den, int64_t* q, int64_t den_hi = time_internal::GetRepHi(den); uint32_t den_lo = time_internal::GetRepLo(den); - if (den_hi == 0 && den_lo == kTicksPerNanosecond) { - // Dividing by 1ns - if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000000000) { - *q = num_hi * 1000000000 + num_lo / kTicksPerNanosecond; - *rem = time_internal::MakeDuration(0, num_lo % den_lo); - return true; - } - } else if (den_hi == 0 && den_lo == 100 * kTicksPerNanosecond) { - // Dividing by 100ns (common when converting to Universal time) - if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 10000000) { - *q = num_hi * 10000000 + num_lo / (100 * kTicksPerNanosecond); - *rem = time_internal::MakeDuration(0, num_lo % den_lo); - return true; - } - } else if (den_hi == 0 && den_lo == 1000 * kTicksPerNanosecond) { - // Dividing by 1us - if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000000) { - *q = num_hi * 1000000 + num_lo / (1000 * kTicksPerNanosecond); - *rem = time_internal::MakeDuration(0, num_lo % den_lo); - return true; - } - } else if (den_hi == 0 && den_lo == 1000000 * kTicksPerNanosecond) { - // Dividing by 1ms - if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000) { - *q = num_hi * 1000 + num_lo / (1000000 * kTicksPerNanosecond); - *rem = time_internal::MakeDuration(0, num_lo % den_lo); - return true; + if (den_hi == 0) { + if (den_lo == kTicksPerNanosecond) { + // Dividing by 1ns + if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000000000) { + *q = num_hi * 1000000000 + num_lo / kTicksPerNanosecond; + *rem = time_internal::MakeDuration(0, num_lo % den_lo); + return true; + } + } else if (den_lo == 100 * kTicksPerNanosecond) { + // Dividing by 100ns (common when converting to Universal time) + if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 10000000) { + *q = num_hi * 10000000 + num_lo / (100 * kTicksPerNanosecond); + *rem = time_internal::MakeDuration(0, num_lo % den_lo); + return true; + } + } else if (den_lo == 1000 * kTicksPerNanosecond) { + // Dividing by 1us + if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000000) { + *q = num_hi * 1000000 + num_lo / (1000 * kTicksPerNanosecond); + *rem = time_internal::MakeDuration(0, num_lo % den_lo); + return true; + } + } else if (den_lo == 1000000 * kTicksPerNanosecond) { + // Dividing by 1ms + if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000) { + *q = num_hi * 1000 + num_lo / (1000000 * kTicksPerNanosecond); + *rem = time_internal::MakeDuration(0, num_lo % den_lo); + return true; + } } } else if (den_hi > 0 && den_lo == 0) { // Dividing by positive multiple of 1s |