1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-03 09:13:20 +03:00

Add support for easily declaring static inline functions

We already had those, but they forced modules to spell out the function
bodies twice.  Eliminate some duplicates we had already grown.

Extracted from a somewhat larger patch from Andres Freund.
This commit is contained in:
Alvaro Herrera
2012-10-08 16:12:27 -03:00
parent 08c8058ce9
commit 976fa10d20
7 changed files with 59 additions and 117 deletions

View File

@@ -73,32 +73,32 @@ struct ListCell
* them as macros, since we want to avoid double-evaluation of macro
* arguments. Therefore, we implement them using static inline functions
* if supported by the compiler, or as regular functions otherwise.
* See STATIC_IF_INLINE in c.h.
*/
#ifdef USE_INLINE
static inline ListCell *
#ifndef USE_INLINE
extern ListCell *list_head(const List *l);
extern ListCell *list_tail(List *l);
extern int list_length(const List *l);
#endif /* USE_INLINE */
#if defined(USE_INLINE) || defined(PG_LIST_INCLUDE_DEFINITIONS)
STATIC_IF_INLINE ListCell *
list_head(const List *l)
{
return l ? l->head : NULL;
}
static inline ListCell *
STATIC_IF_INLINE ListCell *
list_tail(List *l)
{
return l ? l->tail : NULL;
}
static inline int
STATIC_IF_INLINE int
list_length(const List *l)
{
return l ? l->length : 0;
}
#else
extern ListCell *list_head(const List *l);
extern ListCell *list_tail(List *l);
extern int list_length(const List *l);
#endif /* USE_INLINE */
#endif /* USE_INLINE || PG_LIST_INCLUDE_DEFINITIONS */
/*
* NB: There is an unfortunate legacy from a previous incarnation of