Skip to content

Commit b5173c8

Browse files
Abseil Teamderekmauro
authored andcommitted
Export of internal Abseil changes
-- f27dbf50d5db12279ab018f11c93ad1704043006 by Derek Mauro <[email protected]>: Internal change PiperOrigin-RevId: 358298501 -- 864c141a59e20e96234c06700d7519d43bc73d71 by Derek Mauro <[email protected]>: Annotates the duration-to-int64 and duration-to-double conversion functions as "pure" to potentially optimize out repeated calls with the same argument This adds an ABSL_ATTRIBUTE_PURE_FUNCTION macro for this purpose. PiperOrigin-RevId: 358247225 GitOrigin-RevId: f27dbf50d5db12279ab018f11c93ad1704043006 Change-Id: I5c2238911711b15d9d3ae53da44db788f20b402b
1 parent f3697b4 commit b5173c8

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

absl/base/attributes.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,4 +678,25 @@
678678
#define ABSL_CONST_INIT
679679
#endif // ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization)
680680

681+
// ABSL_ATTRIBUTE_PURE_FUNCTION
682+
//
683+
// ABSL_ATTRIBUTE_PURE_FUNCTION is used to annotate declarations of "pure"
684+
// functions. A function is pure if its return value is only a function of its
685+
// arguments. The pure attribute prohibits a function from modifying the state
686+
// of the program that is observable by means other than inspecting the
687+
// function's return value. Declaring such functions with the pure attribute
688+
// allows the compiler to avoid emitting some calls in repeated invocations of
689+
// the function with the same argument values.
690+
//
691+
// Example:
692+
//
693+
// ABSL_ATTRIBUTE_PURE_FUNCTION int64_t ToInt64Milliseconds(Duration d);
694+
#if ABSL_HAVE_CPP_ATTRIBUTE(gnu::pure)
695+
#define ABSL_ATTRIBUTE_PURE_FUNCTION [[gnu::pure]]
696+
#elif ABSL_HAVE_ATTRIBUTE(pure)
697+
#define ABSL_ATTRIBUTE_PURE_FUNCTION __attribute__((pure))
698+
#else
699+
#define ABSL_ATTRIBUTE_PURE_FUNCTION
700+
#endif
701+
681702
#endif // ABSL_BASE_ATTRIBUTES_H_

absl/debugging/internal/stacktrace_powerpc-inl.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ static void **NextStackFrame(void **old_sp, const void *uc) {
132132
reinterpret_cast<const ucontext_t*>(uc);
133133
void **const sp_before_signal =
134134
#if defined(__PPC64__)
135-
reinterpret_cast<void**>(signal_context->uc_mcontext.gp_regs[PT_R1]);
135+
reinterpret_cast<void **>(signal_context->uc_mcontext.gp_regs[PT_R1]);
136136
#else
137-
reinterpret_cast<void**>(signal_context->uc_mcontext.uc_regs->gregs[PT_R1]);
137+
reinterpret_cast<void **>(
138+
signal_context->uc_mcontext.uc_regs->gregs[PT_R1]);
138139
#endif
139140
// Check that alleged sp before signal is nonnull and is reasonably
140141
// aligned.

absl/time/time.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,12 @@ Duration Hours(T n) {
458458
//
459459
// absl::Duration d = absl::Milliseconds(1500);
460460
// int64_t isec = absl::ToInt64Seconds(d); // isec == 1
461-
int64_t ToInt64Nanoseconds(Duration d);
462-
int64_t ToInt64Microseconds(Duration d);
463-
int64_t ToInt64Milliseconds(Duration d);
464-
int64_t ToInt64Seconds(Duration d);
465-
int64_t ToInt64Minutes(Duration d);
466-
int64_t ToInt64Hours(Duration d);
461+
ABSL_ATTRIBUTE_PURE_FUNCTION int64_t ToInt64Nanoseconds(Duration d);
462+
ABSL_ATTRIBUTE_PURE_FUNCTION int64_t ToInt64Microseconds(Duration d);
463+
ABSL_ATTRIBUTE_PURE_FUNCTION int64_t ToInt64Milliseconds(Duration d);
464+
ABSL_ATTRIBUTE_PURE_FUNCTION int64_t ToInt64Seconds(Duration d);
465+
ABSL_ATTRIBUTE_PURE_FUNCTION int64_t ToInt64Minutes(Duration d);
466+
ABSL_ATTRIBUTE_PURE_FUNCTION int64_t ToInt64Hours(Duration d);
467467

468468
// ToDoubleNanoSeconds()
469469
// ToDoubleMicroseconds()
@@ -480,12 +480,12 @@ int64_t ToInt64Hours(Duration d);
480480
//
481481
// absl::Duration d = absl::Milliseconds(1500);
482482
// double dsec = absl::ToDoubleSeconds(d); // dsec == 1.5
483-
double ToDoubleNanoseconds(Duration d);
484-
double ToDoubleMicroseconds(Duration d);
485-
double ToDoubleMilliseconds(Duration d);
486-
double ToDoubleSeconds(Duration d);
487-
double ToDoubleMinutes(Duration d);
488-
double ToDoubleHours(Duration d);
483+
ABSL_ATTRIBUTE_PURE_FUNCTION double ToDoubleNanoseconds(Duration d);
484+
ABSL_ATTRIBUTE_PURE_FUNCTION double ToDoubleMicroseconds(Duration d);
485+
ABSL_ATTRIBUTE_PURE_FUNCTION double ToDoubleMilliseconds(Duration d);
486+
ABSL_ATTRIBUTE_PURE_FUNCTION double ToDoubleSeconds(Duration d);
487+
ABSL_ATTRIBUTE_PURE_FUNCTION double ToDoubleMinutes(Duration d);
488+
ABSL_ATTRIBUTE_PURE_FUNCTION double ToDoubleHours(Duration d);
489489

490490
// FromChrono()
491491
//

0 commit comments

Comments
 (0)