Skip to content

Commit a8593a3

Browse files
committed
Convert MemoryContextSwitchTo() into an inline function when using GCC.
1 parent 477a64d commit a8593a3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/backend/utils/mmgr/mcxt.c

Lines changed: 9 additions & 1 deletion
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.53 2004/12/31 22:02:48 pgsql Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.54 2005/02/18 21:52:33 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -619,7 +619,13 @@ repalloc(void *pointer, Size size)
619619
/*
620620
* MemoryContextSwitchTo
621621
* Returns the current context; installs the given context.
622+
*
623+
* This is inlined when using GCC.
624+
*
625+
* TODO: investigate supporting inlining for some non-GCC compilers.
622626
*/
627+
#ifndef __GNUC__
628+
623629
MemoryContext
624630
MemoryContextSwitchTo(MemoryContext context)
625631
{
@@ -632,6 +638,8 @@ MemoryContextSwitchTo(MemoryContext context)
632638
return old;
633639
}
634640

641+
#endif /* ! __GNUC__ */
642+
635643
/*
636644
* MemoryContextStrdup
637645
* Like strdup(), but allocate from the specified context

src/include/utils/palloc.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Portions Copyright (c) 1996-2005, 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.32 2004/12/31 22:03:46 pgsql Exp $
24+
* $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.33 2005/02/18 21:52:34 tgl Exp $
2525
*
2626
*-------------------------------------------------------------------------
2727
*/
@@ -70,8 +70,26 @@ extern void pfree(void *pointer);
7070

7171
extern void *repalloc(void *pointer, Size size);
7272

73+
/*
74+
* MemoryContextSwitchTo can't be a macro in standard C compilers.
75+
* But we can make it an inline function when using GCC.
76+
*/
77+
#ifdef __GNUC__
78+
79+
static __inline__ MemoryContext
80+
MemoryContextSwitchTo(MemoryContext context)
81+
{
82+
MemoryContext old = CurrentMemoryContext;
83+
CurrentMemoryContext = context;
84+
return old;
85+
}
86+
87+
#else
88+
7389
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
7490

91+
#endif /* __GNUC__ */
92+
7593
/*
7694
* These are like standard strdup() except the copied string is
7795
* allocated in a context, not with malloc().

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy