Commit 1f8da02d by Abseil Team Committed by Copybara-Service

Tagged most functions in absl/time/time.h as ABSL_ATTRIBUTE_CONST_FUNCTION or…

Tagged most functions in absl/time/time.h as ABSL_ATTRIBUTE_CONST_FUNCTION or ABSL_ATTRIBUTE_PURE_FUNCTION

However, both absl_attributes are now unimplemented to avoid breaking existing users.

PiperOrigin-RevId: 496769399
Change-Id: I9c00cb60b885526300d744f9ea7c0f2178f092bb
parent 9a2c7bf9
...@@ -716,26 +716,9 @@ ...@@ -716,26 +716,9 @@
#define ABSL_CONST_INIT #define ABSL_CONST_INIT
#endif #endif
// ABSL_ATTRIBUTE_PURE_FUNCTION // These annotations are not available yet due to fear of breaking code.
//
// ABSL_ATTRIBUTE_PURE_FUNCTION is used to annotate declarations of "pure"
// functions. A function is pure if its return value is only a function of its
// arguments. The pure attribute prohibits a function from modifying the state
// of the program that is observable by means other than inspecting the
// function's return value. Declaring such functions with the pure attribute
// allows the compiler to avoid emitting some calls in repeated invocations of
// the function with the same argument values.
//
// Example:
//
// ABSL_ATTRIBUTE_PURE_FUNCTION int64_t ToInt64Milliseconds(Duration d);
#if ABSL_HAVE_CPP_ATTRIBUTE(gnu::pure)
#define ABSL_ATTRIBUTE_PURE_FUNCTION [[gnu::pure]]
#elif ABSL_HAVE_ATTRIBUTE(pure)
#define ABSL_ATTRIBUTE_PURE_FUNCTION __attribute__((pure))
#else
#define ABSL_ATTRIBUTE_PURE_FUNCTION #define ABSL_ATTRIBUTE_PURE_FUNCTION
#endif #define ABSL_ATTRIBUTE_CONST_FUNCTION
// ABSL_ATTRIBUTE_LIFETIME_BOUND indicates that a resource owned by a function // ABSL_ATTRIBUTE_LIFETIME_BOUND indicates that a resource owned by a function
// parameter or implicit object parameter is retained by the return value of the // parameter or implicit object parameter is retained by the return value of the
......
...@@ -185,9 +185,11 @@ void BM_Time_FromCivil_Absl(benchmark::State& state) { ...@@ -185,9 +185,11 @@ void BM_Time_FromCivil_Absl(benchmark::State& state) {
int i = 0; int i = 0;
while (state.KeepRunning()) { while (state.KeepRunning()) {
if ((i & 1) == 0) { if ((i & 1) == 0) {
absl::FromCivil(absl::CivilSecond(2014, 12, 18, 20, 16, 18), tz); benchmark::DoNotOptimize(
absl::FromCivil(absl::CivilSecond(2014, 12, 18, 20, 16, 18), tz));
} else { } else {
absl::FromCivil(absl::CivilSecond(2013, 11, 15, 18, 30, 27), tz); benchmark::DoNotOptimize(
absl::FromCivil(absl::CivilSecond(2013, 11, 15, 18, 30, 27), tz));
} }
++i; ++i;
} }
...@@ -224,7 +226,8 @@ BENCHMARK(BM_Time_FromCivil_Libc); ...@@ -224,7 +226,8 @@ BENCHMARK(BM_Time_FromCivil_Libc);
void BM_Time_FromCivilUTC_Absl(benchmark::State& state) { void BM_Time_FromCivilUTC_Absl(benchmark::State& state) {
const absl::TimeZone tz = absl::UTCTimeZone(); const absl::TimeZone tz = absl::UTCTimeZone();
while (state.KeepRunning()) { while (state.KeepRunning()) {
absl::FromCivil(absl::CivilSecond(2014, 12, 18, 20, 16, 18), tz); benchmark::DoNotOptimize(
absl::FromCivil(absl::CivilSecond(2014, 12, 18, 20, 16, 18), tz));
} }
} }
BENCHMARK(BM_Time_FromCivilUTC_Absl); BENCHMARK(BM_Time_FromCivilUTC_Absl);
...@@ -235,9 +238,11 @@ void BM_Time_FromCivilDay0_Absl(benchmark::State& state) { ...@@ -235,9 +238,11 @@ void BM_Time_FromCivilDay0_Absl(benchmark::State& state) {
int i = 0; int i = 0;
while (state.KeepRunning()) { while (state.KeepRunning()) {
if ((i & 1) == 0) { if ((i & 1) == 0) {
absl::FromCivil(absl::CivilSecond(2014, 12, 0, 20, 16, 18), tz); benchmark::DoNotOptimize(
absl::FromCivil(absl::CivilSecond(2014, 12, 0, 20, 16, 18), tz));
} else { } else {
absl::FromCivil(absl::CivilSecond(2013, 11, 0, 18, 30, 27), tz); benchmark::DoNotOptimize(
absl::FromCivil(absl::CivilSecond(2013, 11, 0, 18, 30, 27), tz));
} }
++i; ++i;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment