1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-27 07:42:10 +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,14 +73,19 @@ extern void *repalloc(void *pointer, Size size);
/*
* MemoryContextSwitchTo can't be a macro in standard C compilers.
* But we can make it an inline function if the compiler supports it.
* See STATIC_IF_INLINE in c.h.
*
* This file has to be includable by some non-backend code such as
* pg_resetxlog, so don't expose the CurrentMemoryContext reference
* if FRONTEND is defined.
*/
#if defined(USE_INLINE) && !defined(FRONTEND)
#ifndef FRONTEND
static inline MemoryContext
#ifndef USE_INLINE
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
#endif /* !USE_INLINE */
#if defined(USE_INLINE) || defined(MCXT_INCLUDE_DEFINITIONS)
STATIC_IF_INLINE MemoryContext
MemoryContextSwitchTo(MemoryContext context)
{
MemoryContext old = CurrentMemoryContext;
@@ -88,10 +93,9 @@ MemoryContextSwitchTo(MemoryContext context)
CurrentMemoryContext = context;
return old;
}
#else
#endif
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
#endif /* USE_INLINE && !FRONTEND */
#endif /* !FRONTEND */
/*
* These are like standard strdup() except the copied string is

View File

@@ -101,14 +101,21 @@ typedef struct SortSupportData
} SortSupportData;
/* ApplySortComparator should be inlined if possible */
#ifdef USE_INLINE
/*
* ApplySortComparator should be inlined if possible. See STATIC_IF_INLINE
* in c.h.
*/
#ifndef USE_INLINE
extern int ApplySortComparator(Datum datum1, bool isNull1,
Datum datum2, bool isNull2,
SortSupport ssup);
#endif /* !USE_INLINE */
#if defined(USE_INLINE) || defined(SORTSUPPORT_INCLUDE_DEFINITIONS)
/*
* Apply a sort comparator function and return a 3-way comparison result.
* This takes care of handling reverse-sort and NULLs-ordering properly.
*/
static inline int
STATIC_IF_INLINE int
ApplySortComparator(Datum datum1, bool isNull1,
Datum datum2, bool isNull2,
SortSupport ssup)
@@ -140,12 +147,7 @@ ApplySortComparator(Datum datum1, bool isNull1,
return compare;
}
#else
extern int ApplySortComparator(Datum datum1, bool isNull1,
Datum datum2, bool isNull2,
SortSupport ssup);
#endif /* USE_INLINE */
#endif /* USE_INLINE || SORTSUPPORT_INCLUDE_DEFINITIONS */
/* Other functions in utils/sort/sortsupport.c */
extern void PrepareSortSupportComparisonShim(Oid cmpFunc, SortSupport ssup);