Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite08ab7c

Browse files
committed
Support inlining various small performance-critical functions on non-GCC
compilers, by applying a configure check to see if the compiler will acceptan unreferenced "static inline foo ..." function without warnings. It isbelieved that such warnings are the only reason not to declare inlinedfunctions in headers, if the compiler understands "inline" at all.Kurt Harriman
1 parentb95a720 commite08ab7c

File tree

11 files changed

+137
-46
lines changed

11 files changed

+137
-46
lines changed

‎config/c-compiler.m4

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Macros to detect C compiler features
2-
# $PostgreSQL: pgsql/config/c-compiler.m4,v 1.19 2008/06/27 00:36:16 tgl Exp $
2+
# $PostgreSQL: pgsql/config/c-compiler.m4,v 1.20 2010/02/13 02:34:08 tgl Exp $
33

44

55
# PGAC_C_SIGNED
@@ -17,6 +17,30 @@ fi])# PGAC_C_SIGNED
1717

1818

1919

20+
# PGAC_C_INLINE
21+
# -------------
22+
# Check if the C compiler understands inline functions.
23+
# Defines: inline, USE_INLINE
24+
AC_DEFUN([PGAC_C_INLINE],
25+
[AC_C_INLINE
26+
AC_CACHE_CHECK([for quiet inline (no complaint if unreferenced)],pgac_cv_c_inline_quietly,
27+
[pgac_cv_c_inline_quietly=no
28+
if test "$ac_cv_c_inline" != no; then
29+
pgac_c_inline_save_werror=$ac_c_werror_flag
30+
ac_c_werror_flag=yes
31+
AC_LINK_IFELSE([AC_LANG_PROGRAM([static inline int fun () {return 0;}],[])],
32+
[pgac_cv_c_inline_quietly=yes])
33+
ac_c_werror_flag=$pgac_c_inline_save_werror
34+
fi])
35+
if test "$pgac_cv_c_inline_quietly" != no; then
36+
AC_DEFINE_UNQUOTED([USE_INLINE],1,
37+
[Define to 1 if "static inline" works without unwanted warnings from]
38+
[compilations where static inline functions are defined but not called.])
39+
fi
40+
])# PGAC_C_INLINE
41+
42+
43+
2044
# PGAC_TYPE_64BIT_INT(TYPE)
2145
# -------------------------
2246
# Check if TYPE is a working 64 bit integer type. Set HAVE_TYPE_64 to

‎configure

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14535,6 +14535,75 @@ _ACEOF
1453514535
;;
1453614536
esac
1453714537

14538+
{ $as_echo "$as_me:$LINENO: checking for quiet inline (no complaint if unreferenced)" >&5
14539+
$as_echo_n "checking for quiet inline (no complaint if unreferenced)... " >&6; }
14540+
if test "${pgac_cv_c_inline_quietly+set}" = set; then
14541+
$as_echo_n "(cached) " >&6
14542+
else
14543+
pgac_cv_c_inline_quietly=no
14544+
if test "$ac_cv_c_inline" != no; then
14545+
pgac_c_inline_save_werror=$ac_c_werror_flag
14546+
ac_c_werror_flag=yes
14547+
cat >conftest.$ac_ext <<_ACEOF
14548+
/* confdefs.h. */
14549+
_ACEOF
14550+
cat confdefs.h >>conftest.$ac_ext
14551+
cat >>conftest.$ac_ext <<_ACEOF
14552+
/* end confdefs.h. */
14553+
static inline int fun () {return 0;}
14554+
int
14555+
main ()
14556+
{
14557+
14558+
;
14559+
return 0;
14560+
}
14561+
_ACEOF
14562+
rm -f conftest.$ac_objext conftest$ac_exeext
14563+
if { (ac_try="$ac_link"
14564+
case "(($ac_try" in
14565+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
14566+
*) ac_try_echo=$ac_try;;
14567+
esac
14568+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
14569+
$as_echo "$ac_try_echo") >&5
14570+
(eval "$ac_link") 2>conftest.er1
14571+
ac_status=$?
14572+
grep -v '^ *+' conftest.er1 >conftest.err
14573+
rm -f conftest.er1
14574+
cat conftest.err >&5
14575+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
14576+
(exit $ac_status); } && {
14577+
test -z "$ac_c_werror_flag" ||
14578+
test ! -s conftest.err
14579+
} && test -s conftest$ac_exeext && {
14580+
test "$cross_compiling" = yes ||
14581+
$as_test_x conftest$ac_exeext
14582+
}; then
14583+
pgac_cv_c_inline_quietly=yes
14584+
else
14585+
$as_echo "$as_me: failed program was:" >&5
14586+
sed 's/^/| /' conftest.$ac_ext >&5
14587+
14588+
14589+
fi
14590+
14591+
rm -rf conftest.dSYM
14592+
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
14593+
conftest$ac_exeext conftest.$ac_ext
14594+
ac_c_werror_flag=$pgac_c_inline_save_werror
14595+
fi
14596+
fi
14597+
{ $as_echo "$as_me:$LINENO: result: $pgac_cv_c_inline_quietly" >&5
14598+
$as_echo "$pgac_cv_c_inline_quietly" >&6; }
14599+
if test "$pgac_cv_c_inline_quietly" != no; then
14600+
14601+
cat >>confdefs.h <<_ACEOF
14602+
#define USE_INLINE 1
14603+
_ACEOF
14604+
14605+
fi
14606+
1453814607
{ $as_echo "$as_me:$LINENO: checking for preprocessor stringizing operator" >&5
1453914608
$as_echo_n "checking for preprocessor stringizing operator... " >&6; }
1454014609
if test "${ac_cv_c_stringize+set}" = set; then

‎configure.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.621 2010/01/16 19:50:26 tgl Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.622 2010/02/13 02:34:11 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -1087,7 +1087,7 @@ fi
10871087
m4_defun([AC_PROG_CC_STDC], []) dnl We don't want that.
10881088
AC_C_BIGENDIAN
10891089
AC_C_CONST
1090-
AC_C_INLINE
1090+
PGAC_C_INLINE
10911091
AC_C_STRINGIZE
10921092
PGAC_C_SIGNED
10931093
AC_C_VOLATILE

‎src/backend/nodes/list.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/nodes/list.c,v 1.73 2010/01/02 16:57:46 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/nodes/list.c,v 1.74 2010/02/13 02:34:11 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -1224,12 +1224,10 @@ list_copy_tail(List *oldlist, int nskip)
12241224
}
12251225

12261226
/*
1227-
* When using non-GCC compilers, we can't define these as inline
1228-
* functions in pg_list.h, so they are defined here.
1229-
*
1230-
* TODO: investigate supporting inlining for some non-GCC compilers.
1227+
* pg_list.h defines inline versions of these functions if allowed by the
1228+
* compiler; in which case the definitions below are skipped.
12311229
*/
1232-
#ifndef__GNUC__
1230+
#ifndefUSE_INLINE
12331231

12341232
ListCell*
12351233
list_head(List*l)
@@ -1248,7 +1246,7 @@ list_length(List *l)
12481246
{
12491247
returnl ?l->length :0;
12501248
}
1251-
#endif/* !__GNUC__ */
1249+
#endif/* !USE_INLINE */
12521250

12531251
/*
12541252
* Temporary compatibility functions

‎src/backend/utils/mmgr/mcxt.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.68 2010/01/02 16:57:58 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.69 2010/02/13 02:34:12 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -628,11 +628,10 @@ repalloc(void *pointer, Size size)
628628
* MemoryContextSwitchTo
629629
*Returns the current context; installs the given context.
630630
*
631-
* This is inlined when using GCC.
632-
*
633-
* TODO: investigate supporting inlining for some non-GCC compilers.
631+
* palloc.h defines an inline version of this function if allowed by the
632+
* compiler; in which case the definition below is skipped.
634633
*/
635-
#ifndef__GNUC__
634+
#ifndefUSE_INLINE
636635

637636
MemoryContext
638637
MemoryContextSwitchTo(MemoryContextcontext)
@@ -645,7 +644,7 @@ MemoryContextSwitchTo(MemoryContext context)
645644
CurrentMemoryContext=context;
646645
returnold;
647646
}
648-
#endif/* !__GNUC__ */
647+
#endif/* !USE_INLINE */
649648

650649
/*
651650
* MemoryContextStrdup

‎src/include/nodes/pg_list.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
33-
* $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.62 2010/01/02 16:58:04 momjian Exp $
33+
* $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.63 2010/02/13 02:34:13 tgl Exp $
3434
*
3535
*-------------------------------------------------------------------------
3636
*/
@@ -71,24 +71,24 @@ struct ListCell
7171
/*
7272
* These routines are used frequently. However, we can't implement
7373
* them as macros, since we want to avoid double-evaluation of macro
74-
* arguments. Therefore, we implement them usingGCC inline functions,
75-
*andas regular functionswith non-GCC compilers.
74+
* arguments. Therefore, we implement them usingstatic inline functions
75+
*if supported by the compiler, oras regular functionsotherwise.
7676
*/
77-
#ifdef__GNUC__
77+
#ifdefUSE_INLINE
7878

79-
static__inline__ListCell*
79+
staticinlineListCell*
8080
list_head(List*l)
8181
{
8282
returnl ?l->head :NULL;
8383
}
8484

85-
static__inline__ListCell*
85+
staticinlineListCell*
8686
list_tail(List*l)
8787
{
8888
returnl ?l->tail :NULL;
8989
}
9090

91-
static__inline__int
91+
staticinlineint
9292
list_length(List*l)
9393
{
9494
returnl ?l->length :0;
@@ -98,7 +98,7 @@ list_length(List *l)
9898
externListCell*list_head(List*l);
9999
externListCell*list_tail(List*l);
100100
externintlist_length(List*l);
101-
#endif/*__GNUC__ */
101+
#endif/*USE_INLINE */
102102

103103
/*
104104
* NB: There is an unfortunate legacy from a previous incarnation of

‎src/include/pg_config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,10 @@
749749
(--enable-float8-byval) */
750750
#undef USE_FLOAT8_BYVAL
751751

752+
/* Define to 1 if "static inline" works without unwanted warnings from
753+
compilations where static inline functions are defined but not called. */
754+
#undef USE_INLINE
755+
752756
/* Define to 1 if you want 64-bit integer timestamp and interval support.
753757
(--enable-integer-datetimes) */
754758
#undef USE_INTEGER_DATETIMES

‎src/include/pg_config.h.win32

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*
77
* HAVE_CBRT, HAVE_FUNCNAME_FUNC, HAVE_GETOPT, HAVE_GETOPT_H,
88
* HAVE_GETOPT_LONG, HAVE_RINT, HAVE_STRINGS_H, HAVE_STRTOLL,
9-
* HAVE_STRTOULL, HAVE_STRUCT_OPTION, ENABLE_THREAD_SAFETY
10-
*
9+
* HAVE_STRTOULL, HAVE_STRUCT_OPTION, ENABLE_THREAD_SAFETY,
10+
* USE_INLINE, inline
1111
*/
1212

1313
/* Define to the type of arg 1 of 'accept' */
@@ -621,6 +621,10 @@
621621
/* Define to 1 to build with Bonjour support. (--with-bonjour) */
622622
/* #undef USE_BONJOUR */
623623

624+
/* Define to 1 if "static inline" works without unwanted warnings from
625+
compilations where static inline functions are defined but not called. */
626+
#define USE_INLINE 1
627+
624628
/* Define to 1 if you want 64-bit integer timestamp and interval support.
625629
(--enable-integer-datetimes) */
626630
/* #undef USE_INTEGER_DATETIMES */
@@ -664,9 +668,11 @@
664668
/* Define to empty if `const' does not conform to ANSI C. */
665669
/* #undef const */
666670

667-
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
668-
if it is not supported. */
669-
/* #undef inline */
671+
/* Define to `__inline__' or `__inline' if that's what the C compiler
672+
calls it, or to nothing if 'inline' is not supported under any name. */
673+
#ifndef __cplusplus
674+
#define inline __inline
675+
#endif
670676

671677
/* Define to empty if the C compiler does not understand signed types. */
672678
/* #undef signed */

‎src/include/port/win32.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.91 2010/01/02 22:47:37 mha Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.92 2010/02/13 02:34:14 tgl Exp $ */
22

33
#if defined(_MSC_VER)|| defined(__BORLANDC__)
44
#defineWIN32_ONLY_COMPILER
@@ -313,15 +313,6 @@ typedef __int64 ssize_t;
313313
typedefunsigned shortmode_t;
314314
#endif
315315

316-
/*
317-
*Certain "standard edition" versions of MSVC throw a warning
318-
*that later generates an error for "inline" statements, but
319-
*__inline seems to work. e.g. Microsoft Visual C++ .NET
320-
*Version 7.1.3088
321-
*/
322-
#defineinline __inline
323-
#define__inline__ __inline
324-
325316
#ifndef__BORLANDC__
326317
#define_S_IRWXU(_S_IREAD | _S_IWRITE | _S_IEXEC)
327318
#define_S_IXUSR_S_IEXEC

‎src/include/portability/instr_time.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*
4646
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
4747
*
48-
* $PostgreSQL: pgsql/src/include/portability/instr_time.h,v 1.5 2010/01/02 16:58:08 momjian Exp $
48+
* $PostgreSQL: pgsql/src/include/portability/instr_time.h,v 1.6 2010/02/13 02:34:15 tgl Exp $
4949
*
5050
*-------------------------------------------------------------------------
5151
*/
@@ -141,7 +141,7 @@ typedef LARGE_INTEGER instr_time;
141141
#defineINSTR_TIME_GET_MICROSEC(t) \
142142
((uint64) (((double) (t).QuadPart * 1000000.0) / GetTimerFrequency()))
143143

144-
static__inline__double
144+
staticinlinedouble
145145
GetTimerFrequency(void)
146146
{
147147
LARGE_INTEGERf;

‎src/include/utils/palloc.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
2222
* Portions Copyright (c) 1994, Regents of the University of California
2323
*
24-
* $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.42 2010/01/02 16:58:10 momjian Exp $
24+
* $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.43 2010/02/13 02:34:16 tgl Exp $
2525
*
2626
*-------------------------------------------------------------------------
2727
*/
@@ -72,11 +72,11 @@ extern void *repalloc(void *pointer, Size size);
7272

7373
/*
7474
* MemoryContextSwitchTo can't be a macro in standard C compilers.
75-
* But we can make it an inline functionwhen using GCC.
75+
* But we can make it an inline functionif the compiler supports it.
7676
*/
77-
#ifdef__GNUC__
77+
#ifdefUSE_INLINE
7878

79-
static__inline__MemoryContext
79+
staticinlineMemoryContext
8080
MemoryContextSwitchTo(MemoryContextcontext)
8181
{
8282
MemoryContextold=CurrentMemoryContext;
@@ -87,7 +87,7 @@ MemoryContextSwitchTo(MemoryContext context)
8787
#else
8888

8989
externMemoryContextMemoryContextSwitchTo(MemoryContextcontext);
90-
#endif/*__GNUC__ */
90+
#endif/*USE_INLINE */
9191

9292
/*
9393
* These are like standard strdup() except the copied string is

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp