1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Support inlining various small performance-critical functions on non-GCC

compilers, by applying a configure check to see if the compiler will accept
an unreferenced "static inline foo ..." function without warnings.  It is
believed that such warnings are the only reason not to declare inlined
functions in headers, if the compiler understands "inline" at all.

Kurt Harriman
This commit is contained in:
Tom Lane
2010-02-13 02:34:16 +00:00
parent b95a720a48
commit e08ab7c312
11 changed files with 137 additions and 46 deletions

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/list.c,v 1.73 2010/01/02 16:57:46 momjian Exp $
* $PostgreSQL: pgsql/src/backend/nodes/list.c,v 1.74 2010/02/13 02:34:11 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1224,12 +1224,10 @@ list_copy_tail(List *oldlist, int nskip)
}
/*
* When using non-GCC compilers, we can't define these as inline
* functions in pg_list.h, so they are defined here.
*
* TODO: investigate supporting inlining for some non-GCC compilers.
* pg_list.h defines inline versions of these functions if allowed by the
* compiler; in which case the definitions below are skipped.
*/
#ifndef __GNUC__
#ifndef USE_INLINE
ListCell *
list_head(List *l)
@ -1248,7 +1246,7 @@ list_length(List *l)
{
return l ? l->length : 0;
}
#endif /* ! __GNUC__ */
#endif /* ! USE_INLINE */
/*
* Temporary compatibility functions

View File

@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.68 2010/01/02 16:57:58 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.69 2010/02/13 02:34:12 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -628,11 +628,10 @@ repalloc(void *pointer, Size size)
* MemoryContextSwitchTo
* Returns the current context; installs the given context.
*
* This is inlined when using GCC.
*
* TODO: investigate supporting inlining for some non-GCC compilers.
* palloc.h defines an inline version of this function if allowed by the
* compiler; in which case the definition below is skipped.
*/
#ifndef __GNUC__
#ifndef USE_INLINE
MemoryContext
MemoryContextSwitchTo(MemoryContext context)
@ -645,7 +644,7 @@ MemoryContextSwitchTo(MemoryContext context)
CurrentMemoryContext = context;
return old;
}
#endif /* ! __GNUC__ */
#endif /* ! USE_INLINE */
/*
* MemoryContextStrdup

View File

@ -30,7 +30,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.62 2010/01/02 16:58:04 momjian Exp $
* $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.63 2010/02/13 02:34:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -71,24 +71,24 @@ struct ListCell
/*
* These routines are used frequently. However, we can't implement
* them as macros, since we want to avoid double-evaluation of macro
* arguments. Therefore, we implement them using GCC inline functions,
* and as regular functions with non-GCC compilers.
* arguments. Therefore, we implement them using static inline functions
* if supported by the compiler, or as regular functions otherwise.
*/
#ifdef __GNUC__
#ifdef USE_INLINE
static __inline__ ListCell *
static inline ListCell *
list_head(List *l)
{
return l ? l->head : NULL;
}
static __inline__ ListCell *
static inline ListCell *
list_tail(List *l)
{
return l ? l->tail : NULL;
}
static __inline__ int
static inline int
list_length(List *l)
{
return l ? l->length : 0;
@ -98,7 +98,7 @@ list_length(List *l)
extern ListCell *list_head(List *l);
extern ListCell *list_tail(List *l);
extern int list_length(List *l);
#endif /* __GNUC__ */
#endif /* USE_INLINE */
/*
* NB: There is an unfortunate legacy from a previous incarnation of

View File

@ -749,6 +749,10 @@
(--enable-float8-byval) */
#undef USE_FLOAT8_BYVAL
/* Define to 1 if "static inline" works without unwanted warnings from
compilations where static inline functions are defined but not called. */
#undef USE_INLINE
/* Define to 1 if you want 64-bit integer timestamp and interval support.
(--enable-integer-datetimes) */
#undef USE_INTEGER_DATETIMES

View File

@ -6,8 +6,8 @@
*
* HAVE_CBRT, HAVE_FUNCNAME_FUNC, HAVE_GETOPT, HAVE_GETOPT_H,
* HAVE_GETOPT_LONG, HAVE_RINT, HAVE_STRINGS_H, HAVE_STRTOLL,
* HAVE_STRTOULL, HAVE_STRUCT_OPTION, ENABLE_THREAD_SAFETY
*
* HAVE_STRTOULL, HAVE_STRUCT_OPTION, ENABLE_THREAD_SAFETY,
* USE_INLINE, inline
*/
/* Define to the type of arg 1 of 'accept' */
@ -621,6 +621,10 @@
/* Define to 1 to build with Bonjour support. (--with-bonjour) */
/* #undef USE_BONJOUR */
/* Define to 1 if "static inline" works without unwanted warnings from
compilations where static inline functions are defined but not called. */
#define USE_INLINE 1
/* Define to 1 if you want 64-bit integer timestamp and interval support.
(--enable-integer-datetimes) */
/* #undef USE_INTEGER_DATETIMES */
@ -664,9 +668,11 @@
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
if it is not supported. */
/* #undef inline */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
#define inline __inline
#endif
/* Define to empty if the C compiler does not understand signed types. */
/* #undef signed */

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.91 2010/01/02 22:47:37 mha Exp $ */
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.92 2010/02/13 02:34:14 tgl Exp $ */
#if defined(_MSC_VER) || defined(__BORLANDC__)
#define WIN32_ONLY_COMPILER
@ -313,15 +313,6 @@ typedef __int64 ssize_t;
typedef unsigned short mode_t;
#endif
/*
* Certain "standard edition" versions of MSVC throw a warning
* that later generates an error for "inline" statements, but
* __inline seems to work. e.g. Microsoft Visual C++ .NET
* Version 7.1.3088
*/
#define inline __inline
#define __inline__ __inline
#ifndef __BORLANDC__
#define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
#define _S_IXUSR _S_IEXEC

View File

@ -45,7 +45,7 @@
*
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/include/portability/instr_time.h,v 1.5 2010/01/02 16:58:08 momjian Exp $
* $PostgreSQL: pgsql/src/include/portability/instr_time.h,v 1.6 2010/02/13 02:34:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -141,7 +141,7 @@ typedef LARGE_INTEGER instr_time;
#define INSTR_TIME_GET_MICROSEC(t) \
((uint64) (((double) (t).QuadPart * 1000000.0) / GetTimerFrequency()))
static __inline__ double
static inline double
GetTimerFrequency(void)
{
LARGE_INTEGER f;

View File

@ -21,7 +21,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.42 2010/01/02 16:58:10 momjian Exp $
* $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.43 2010/02/13 02:34:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -72,11 +72,11 @@ 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 when using GCC.
* But we can make it an inline function if the compiler supports it.
*/
#ifdef __GNUC__
#ifdef USE_INLINE
static __inline__ MemoryContext
static inline MemoryContext
MemoryContextSwitchTo(MemoryContext context)
{
MemoryContext old = CurrentMemoryContext;
@ -87,7 +87,7 @@ MemoryContextSwitchTo(MemoryContext context)
#else
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
#endif /* __GNUC__ */
#endif /* USE_INLINE */
/*
* These are like standard strdup() except the copied string is