Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3077)

Unified Diff: base/time/time.h

Issue 1250453004: Revert of Base: Make TimeDelta constructors deal with overflow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/time/time.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time.h
diff --git a/base/time/time.h b/base/time/time.h
index e0a6ea37eaa9f2c2035a8b04ad80b9d3d7818223..a02fbeb01ffb7e82761d524fd8c8bcacb9f618eb 100644
--- a/base/time/time.h
+++ b/base/time/time.h
@@ -264,9 +264,6 @@
explicit TimeDelta(int64 delta_us) : delta_(delta_us) {
}
- // Private method to build a delta from a double.
- static TimeDelta FromDouble(double value);
-
// Delta in microseconds.
int64 delta_;
};
@@ -600,6 +597,7 @@
// static
inline TimeDelta TimeDelta::FromDays(int days) {
+ // Preserve max to prevent overflow.
if (days == std::numeric_limits<int>::max())
return Max();
return TimeDelta(days * Time::kMicrosecondsPerDay);
@@ -607,6 +605,7 @@
// static
inline TimeDelta TimeDelta::FromHours(int hours) {
+ // Preserve max to prevent overflow.
if (hours == std::numeric_limits<int>::max())
return Max();
return TimeDelta(hours * Time::kMicrosecondsPerHour);
@@ -614,6 +613,7 @@
// static
inline TimeDelta TimeDelta::FromMinutes(int minutes) {
+ // Preserve max to prevent overflow.
if (minutes == std::numeric_limits<int>::max())
return Max();
return TimeDelta(minutes * Time::kMicrosecondsPerMinute);
@@ -621,38 +621,42 @@
// static
inline TimeDelta TimeDelta::FromSeconds(int64 secs) {
- return TimeDelta(secs) * Time::kMicrosecondsPerSecond;
+ // Preserve max to prevent overflow.
+ if (secs == std::numeric_limits<int64>::max())
+ return Max();
+ return TimeDelta(secs * Time::kMicrosecondsPerSecond);
}
// static
inline TimeDelta TimeDelta::FromMilliseconds(int64 ms) {
- return TimeDelta(ms) * Time::kMicrosecondsPerMillisecond;
+ // Preserve max to prevent overflow.
+ if (ms == std::numeric_limits<int64>::max())
+ return Max();
+ return TimeDelta(ms * Time::kMicrosecondsPerMillisecond);
}
// static
inline TimeDelta TimeDelta::FromSecondsD(double secs) {
- return FromDouble(secs * Time::kMicrosecondsPerSecond);
+ // Preserve max to prevent overflow.
+ if (secs == std::numeric_limits<double>::infinity())
+ return Max();
+ return TimeDelta(static_cast<int64>(secs * Time::kMicrosecondsPerSecond));
}
// static
inline TimeDelta TimeDelta::FromMillisecondsD(double ms) {
- return FromDouble(ms * Time::kMicrosecondsPerMillisecond);
+ // Preserve max to prevent overflow.
+ if (ms == std::numeric_limits<double>::infinity())
+ return Max();
+ return TimeDelta(static_cast<int64>(ms * Time::kMicrosecondsPerMillisecond));
}
// static
inline TimeDelta TimeDelta::FromMicroseconds(int64 us) {
+ // Preserve max to prevent overflow.
+ if (us == std::numeric_limits<int64>::max())
+ return Max();
return TimeDelta(us);
-}
-
-// static
-inline TimeDelta TimeDelta::FromDouble(double value) {
- double max_magnitude = std::numeric_limits<int64>::max();
- TimeDelta delta = TimeDelta(static_cast<int64>(value));
- if (value > max_magnitude)
- delta = Max();
- else if (value < -max_magnitude)
- delta = -Max();
- return delta;
}
// For logging use only.
« no previous file with comments | « no previous file | base/time/time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698