Skip to content

Commit d30f578

Browse files
Abseil Teamcopybara-github
authored andcommitted
Move Duration ToInt64<unit> functions to be inline.
PiperOrigin-RevId: 706782054 Change-Id: Iade7f9068a81df57d7b84df9ea50e088e33cac9c
1 parent 85c701d commit d30f578

File tree

2 files changed

+56
-50
lines changed

2 files changed

+56
-50
lines changed

absl/time/duration.cc

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -549,50 +549,6 @@ Duration DurationFromTimeval(timeval tv) {
549549
//
550550
// Conversion to other duration types.
551551
//
552-
553-
int64_t ToInt64Nanoseconds(Duration d) {
554-
if (time_internal::GetRepHi(d) >= 0 &&
555-
time_internal::GetRepHi(d) >> 33 == 0) {
556-
return (time_internal::GetRepHi(d) * 1000 * 1000 * 1000) +
557-
(time_internal::GetRepLo(d) / kTicksPerNanosecond);
558-
}
559-
return d / Nanoseconds(1);
560-
}
561-
int64_t ToInt64Microseconds(Duration d) {
562-
if (time_internal::GetRepHi(d) >= 0 &&
563-
time_internal::GetRepHi(d) >> 43 == 0) {
564-
return (time_internal::GetRepHi(d) * 1000 * 1000) +
565-
(time_internal::GetRepLo(d) / (kTicksPerNanosecond * 1000));
566-
}
567-
return d / Microseconds(1);
568-
}
569-
int64_t ToInt64Milliseconds(Duration d) {
570-
if (time_internal::GetRepHi(d) >= 0 &&
571-
time_internal::GetRepHi(d) >> 53 == 0) {
572-
return (time_internal::GetRepHi(d) * 1000) +
573-
(time_internal::GetRepLo(d) / (kTicksPerNanosecond * 1000 * 1000));
574-
}
575-
return d / Milliseconds(1);
576-
}
577-
int64_t ToInt64Seconds(Duration d) {
578-
int64_t hi = time_internal::GetRepHi(d);
579-
if (time_internal::IsInfiniteDuration(d)) return hi;
580-
if (hi < 0 && time_internal::GetRepLo(d) != 0) ++hi;
581-
return hi;
582-
}
583-
int64_t ToInt64Minutes(Duration d) {
584-
int64_t hi = time_internal::GetRepHi(d);
585-
if (time_internal::IsInfiniteDuration(d)) return hi;
586-
if (hi < 0 && time_internal::GetRepLo(d) != 0) ++hi;
587-
return hi / 60;
588-
}
589-
int64_t ToInt64Hours(Duration d) {
590-
int64_t hi = time_internal::GetRepHi(d);
591-
if (time_internal::IsInfiniteDuration(d)) return hi;
592-
if (hi < 0 && time_internal::GetRepLo(d) != 0) ++hi;
593-
return hi / (60 * 60);
594-
}
595-
596552
double ToDoubleNanoseconds(Duration d) {
597553
return FDivDuration(d, Nanoseconds(1));
598554
}

absl/time/time.h

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,12 @@ ABSL_ATTRIBUTE_CONST_FUNCTION Duration Hours(T n) {
620620
//
621621
// absl::Duration d = absl::Milliseconds(1500);
622622
// int64_t isec = absl::ToInt64Seconds(d); // isec == 1
623-
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Nanoseconds(Duration d);
624-
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Microseconds(Duration d);
625-
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Milliseconds(Duration d);
626-
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Seconds(Duration d);
627-
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Minutes(Duration d);
628-
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Hours(Duration d);
623+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Nanoseconds(Duration d);
624+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Microseconds(Duration d);
625+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Milliseconds(Duration d);
626+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Seconds(Duration d);
627+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Minutes(Duration d);
628+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Hours(Duration d);
629629

630630
// ToDoubleNanoseconds()
631631
// ToDoubleMicroseconds()
@@ -1864,6 +1864,56 @@ ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromTimeT(time_t t) {
18641864
return time_internal::FromUnixDuration(Seconds(t));
18651865
}
18661866

1867+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Nanoseconds(Duration d) {
1868+
if (time_internal::GetRepHi(d) >= 0 &&
1869+
time_internal::GetRepHi(d) >> 33 == 0) {
1870+
return (time_internal::GetRepHi(d) * 1000 * 1000 * 1000) +
1871+
(time_internal::GetRepLo(d) / time_internal::kTicksPerNanosecond);
1872+
}
1873+
return d / Nanoseconds(1);
1874+
}
1875+
1876+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Microseconds(Duration d) {
1877+
if (time_internal::GetRepHi(d) >= 0 &&
1878+
time_internal::GetRepHi(d) >> 43 == 0) {
1879+
return (time_internal::GetRepHi(d) * 1000 * 1000) +
1880+
(time_internal::GetRepLo(d) /
1881+
(time_internal::kTicksPerNanosecond * 1000));
1882+
}
1883+
return d / Microseconds(1);
1884+
}
1885+
1886+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Milliseconds(Duration d) {
1887+
if (time_internal::GetRepHi(d) >= 0 &&
1888+
time_internal::GetRepHi(d) >> 53 == 0) {
1889+
return (time_internal::GetRepHi(d) * 1000) +
1890+
(time_internal::GetRepLo(d) /
1891+
(time_internal::kTicksPerNanosecond * 1000 * 1000));
1892+
}
1893+
return d / Milliseconds(1);
1894+
}
1895+
1896+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Seconds(Duration d) {
1897+
int64_t hi = time_internal::GetRepHi(d);
1898+
if (time_internal::IsInfiniteDuration(d)) return hi;
1899+
if (hi < 0 && time_internal::GetRepLo(d) != 0) ++hi;
1900+
return hi;
1901+
}
1902+
1903+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Minutes(Duration d) {
1904+
int64_t hi = time_internal::GetRepHi(d);
1905+
if (time_internal::IsInfiniteDuration(d)) return hi;
1906+
if (hi < 0 && time_internal::GetRepLo(d) != 0) ++hi;
1907+
return hi / 60;
1908+
}
1909+
1910+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Hours(Duration d) {
1911+
int64_t hi = time_internal::GetRepHi(d);
1912+
if (time_internal::IsInfiniteDuration(d)) return hi;
1913+
if (hi < 0 && time_internal::GetRepLo(d) != 0) ++hi;
1914+
return hi / (60 * 60);
1915+
}
1916+
18671917
ABSL_NAMESPACE_END
18681918
} // namespace absl
18691919

0 commit comments

Comments
 (0)