blob: cf4562a12f5b48fe1d88f749144571cea1e3bec1 (
plain) (
tree)
|
|
From da6e3f6071fdabeb96c0805626418414b4a4cea8 Mon Sep 17 00:00:00 2001
From: Stephan Hartmann <stha09@googlemail.com>
Date: Wed, 9 Feb 2022 17:56:21 +0000
Subject: [PATCH] GCC: make base::InMilliseconds(F,RoundedUp) constexpr
media::DecodeTimestamp uses it in several constexpr methods.
---
base/time/time.cc | 24 ------------------------
base/time/time.h | 30 +++++++++++++++++++++++++++---
2 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/base/time/time.cc b/base/time/time.cc
index 0de273e..e0acda2 100644
--- a/base/time/time.cc
+++ b/base/time/time.cc
@@ -74,30 +74,6 @@ int TimeDelta::InDaysFloored() const {
: std::numeric_limits<int>::max();
}
-double TimeDelta::InMillisecondsF() const {
- if (!is_inf())
- return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond;
- return (delta_ < 0) ? -std::numeric_limits<double>::infinity()
- : std::numeric_limits<double>::infinity();
-}
-
-int64_t TimeDelta::InMilliseconds() const {
- if (!is_inf())
- return delta_ / Time::kMicrosecondsPerMillisecond;
- return (delta_ < 0) ? std::numeric_limits<int64_t>::min()
- : std::numeric_limits<int64_t>::max();
-}
-
-int64_t TimeDelta::InMillisecondsRoundedUp() const {
- if (!is_inf()) {
- const int64_t result = delta_ / Time::kMicrosecondsPerMillisecond;
- // Convert |result| from truncating to ceiling.
- return (delta_ > result * Time::kMicrosecondsPerMillisecond) ? (result + 1)
- : result;
- }
- return delta_;
-}
-
double TimeDelta::InMicrosecondsF() const {
if (!is_inf())
return static_cast<double>(delta_);
diff --git a/base/time/time.h b/base/time/time.h
index c027aab..fb1d78d 100644
--- a/base/time/time.h
+++ b/base/time/time.h
@@ -216,9 +216,9 @@ class BASE_EXPORT TimeDelta {
constexpr int InMinutes() const;
constexpr double InSecondsF() const;
constexpr int64_t InSeconds() const;
- double InMillisecondsF() const;
- int64_t InMilliseconds() const;
- int64_t InMillisecondsRoundedUp() const;
+ constexpr double InMillisecondsF() const;
+ constexpr int64_t InMilliseconds() const;
+ constexpr int64_t InMillisecondsRoundedUp() const;
constexpr int64_t InMicroseconds() const { return delta_; }
double InMicrosecondsF() const;
constexpr int64_t InNanoseconds() const;
@@ -889,6 +889,30 @@ constexpr int64_t TimeDelta::InSeconds() const {
return is_inf() ? delta_ : (delta_ / Time::kMicrosecondsPerSecond);
}
+constexpr double TimeDelta::InMillisecondsF() const {
+ if (!is_inf())
+ return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond;
+ return (delta_ < 0) ? -std::numeric_limits<double>::infinity()
+ : std::numeric_limits<double>::infinity();
+}
+
+constexpr int64_t TimeDelta::InMilliseconds() const {
+ if (!is_inf())
+ return delta_ / Time::kMicrosecondsPerMillisecond;
+ return (delta_ < 0) ? std::numeric_limits<int64_t>::min()
+ : std::numeric_limits<int64_t>::max();
+}
+
+constexpr int64_t TimeDelta::InMillisecondsRoundedUp() const {
+ if (!is_inf()) {
+ const int64_t result = delta_ / Time::kMicrosecondsPerMillisecond;
+ // Convert |result| from truncating to ceiling.
+ return (delta_ > result * Time::kMicrosecondsPerMillisecond) ? (result + 1)
+ : result;
+ }
+ return delta_;
+}
+
constexpr int64_t TimeDelta::InNanoseconds() const {
return base::ClampMul(delta_, Time::kNanosecondsPerMicrosecond);
}
--
2.34.1
|