diff options
author | David Lamparter <equinox@diac24.net> | 2019-05-21 04:48:30 +0200 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2019-05-21 05:42:13 +0200 |
commit | 3b18b6c03d0243d9d161d17b875b0bb4c6587f1e (patch) | |
tree | eba4a1ac235f8155150d4922c2708a18fbb1b55b /lib/compiler.h | |
parent | lib/table: remove odd casts (diff) | |
download | frr-3b18b6c03d0243d9d161d17b875b0bb4c6587f1e.tar.xz frr-3b18b6c03d0243d9d161d17b875b0bb4c6587f1e.zip |
lib/table: remove nonsensical const, add pure
Passing the struct route_table *ptr as const doesn't really help; if
anything it semantically would imply that the returned route_node is
const too since constness should propagate (but it doesn't in C.)
The right thing to do here - which actually helps the compiler optimize
the code too - is to tag functions with __attribute__((pure)). The
compiler does this automatically if it has the function body (and the
body of all called functions) available. That should cover most "static
inline" functions in headers, as well as functions in the same file.
However, this doesn't work (at least without LTO) for extern functions.
Hence, add "ext_pure" for this case. (Built-in "extern" to make lines
shorter.)
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/compiler.h')
-rw-r--r-- | lib/compiler.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/compiler.h b/lib/compiler.h index 474adc7c8..c2e57db7f 100644 --- a/lib/compiler.h +++ b/lib/compiler.h @@ -76,6 +76,15 @@ extern "C" { #define _DEPRECATED(x) deprecated #endif +/* pure = function does not modify memory & return value is the same if + * memory hasn't changed (=> allows compiler to optimize) + * + * Mostly autodetected by the compiler if function body is available (i.e. + * static inline functions in headers). Since that implies it should only be + * used in headers for non-inline functions, the "extern" is included here. + */ +#define ext_pure extern __attribute__((pure)) + /* for helper functions defined inside macros */ #define macro_inline static inline __attribute__((unused)) #define macro_pure static inline __attribute__((unused, pure)) |