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/table.h | |
| parent | 0734f93b8ed51de625720346c953bd50e9f40487 (diff) | |
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/table.h')
| -rw-r--r-- | lib/table.h | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/lib/table.h b/lib/table.h index 3e3fb658ae..14be7ab656 100644 --- a/lib/table.h +++ b/lib/table.h @@ -198,26 +198,29 @@ static inline void route_table_set_info(struct route_table *table, void *d) table->info = d; } +/* ext_pure => extern __attribute__((pure)) + * does not modify memory (but depends on mem), allows compiler to optimize + */ + extern void route_table_finish(struct route_table *table); -extern struct route_node *route_top(struct route_table *table); -extern struct route_node *route_next(struct route_node *node); -extern struct route_node *route_next_until(struct route_node *node, - const struct route_node *limit); -extern struct route_node *route_node_get(struct route_table *const table, +ext_pure struct route_node *route_top(struct route_table *table); +ext_pure struct route_node *route_next(struct route_node *node); +ext_pure struct route_node *route_next_until(struct route_node *node, + const struct route_node *limit); +extern struct route_node *route_node_get(struct route_table *table, union prefixconstptr pu); -extern struct route_node *route_node_lookup(const struct route_table *table, - union prefixconstptr pu); -extern struct route_node * -route_node_lookup_maynull(const struct route_table *table, - union prefixconstptr pu); -extern struct route_node *route_node_match(const struct route_table *table, - union prefixconstptr pu); -extern struct route_node *route_node_match_ipv4(const struct route_table *table, - const struct in_addr *addr); -extern struct route_node *route_node_match_ipv6(const struct route_table *table, - const struct in6_addr *addr); - -extern unsigned long route_table_count(const struct route_table *table); +ext_pure struct route_node *route_node_lookup(struct route_table *table, + union prefixconstptr pu); +ext_pure struct route_node *route_node_lookup_maynull(struct route_table *table, + union prefixconstptr pu); +ext_pure struct route_node *route_node_match(struct route_table *table, + union prefixconstptr pu); +ext_pure struct route_node *route_node_match_ipv4(struct route_table *table, + const struct in_addr *addr); +ext_pure struct route_node *route_node_match_ipv6(struct route_table *table, + const struct in6_addr *addr); + +ext_pure unsigned long route_table_count(struct route_table *table); extern struct route_node *route_node_create(route_table_delegate_t *delegate, struct route_table *table); @@ -226,10 +229,10 @@ extern void route_node_destroy(route_table_delegate_t *delegate, struct route_table *table, struct route_node *node); -extern struct route_node *route_table_get_next(const struct route_table *table, - union prefixconstptr pu); -extern int route_table_prefix_iter_cmp(const struct prefix *p1, - const struct prefix *p2); +ext_pure struct route_node *route_table_get_next(struct route_table *table, + union prefixconstptr pu); +ext_pure int route_table_prefix_iter_cmp(const struct prefix *p1, + const struct prefix *p2); /* * Iterator functions. |
