diff options
author | Abseil Team <absl-team@google.com> | 2021-02-18 17:10:44 -0800 |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2021-02-18 20:12:44 -0500 |
commit | b5173c8d45bbb1eae9900eea6231823041cac64f (patch) | |
tree | 2c77d97d1d71034368d74afac5ab86282ff569c2 /absl/base | |
parent | f3697b4fedc2d8f2311eaaebed051f6a44182bb2 (diff) |
Export of internal Abseil changes
--
f27dbf50d5db12279ab018f11c93ad1704043006 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 358298501
--
864c141a59e20e96234c06700d7519d43bc73d71 by Derek Mauro <dmauro@google.com>:
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
Diffstat (limited to 'absl/base')
-rw-r--r-- | absl/base/attributes.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/absl/base/attributes.h b/absl/base/attributes.h index faa5b27e..cf2cb550 100644 --- a/absl/base/attributes.h +++ b/absl/base/attributes.h @@ -678,4 +678,25 @@ #define ABSL_CONST_INIT #endif // ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization) +// ABSL_ATTRIBUTE_PURE_FUNCTION +// +// 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 +#endif + #endif // ABSL_BASE_ATTRIBUTES_H_ |