diff options
author | Tom Lane | 2005-02-18 21:52:34 +0000 |
---|---|---|
committer | Tom Lane | 2005-02-18 21:52:34 +0000 |
commit | e387bf1a66ea10e1bb65a26f9d97813c02c68a09 (patch) | |
tree | 0d066f6d93a5f3beecfaf5a732f377ea7cc90ddf | |
parent | 4995d0a81c15f80cfe32d746be7af02fc4981a15 (diff) |
Convert MemoryContextSwitchTo() into an inline function when using GCC.
-rw-r--r-- | src/backend/utils/mmgr/mcxt.c | 8 | ||||
-rw-r--r-- | src/include/utils/palloc.h | 18 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 88d4de3462..925fdb9868 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -619,7 +619,13 @@ 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. */ +#ifndef __GNUC__ + MemoryContext MemoryContextSwitchTo(MemoryContext context) { @@ -632,6 +638,8 @@ MemoryContextSwitchTo(MemoryContext context) return old; } +#endif /* ! __GNUC__ */ + /* * MemoryContextStrdup * Like strdup(), but allocate from the specified context diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index 6176745d81..8b9ea05d14 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -70,8 +70,26 @@ extern void pfree(void *pointer); 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. + */ +#ifdef __GNUC__ + +static __inline__ MemoryContext +MemoryContextSwitchTo(MemoryContext context) +{ + MemoryContext old = CurrentMemoryContext; + CurrentMemoryContext = context; + return old; +} + +#else + extern MemoryContext MemoryContextSwitchTo(MemoryContext context); +#endif /* __GNUC__ */ + /* * These are like standard strdup() except the copied string is * allocated in a context, not with malloc(). |