diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-02-18 21:52:34 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-02-18 21:52:34 +0000 |
commit | a8593a34632ab64b9a5e347de6d20f6bab452217 (patch) | |
tree | 507ba3321e329c03c759c5aad79819a69bb871d4 | |
parent | 477a64d9c8f8e11f8418911cfe054f0a135f1306 (diff) | |
download | postgresql-a8593a34632ab64b9a5e347de6d20f6bab452217.tar.gz postgresql-a8593a34632ab64b9a5e347de6d20f6bab452217.zip |
Convert MemoryContextSwitchTo() into an inline function when using GCC.
-rw-r--r-- | src/backend/utils/mmgr/mcxt.c | 10 | ||||
-rw-r--r-- | src/include/utils/palloc.h | 20 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 6ead279fa16..c5a2311bc5e 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.53 2004/12/31 22:02:48 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.54 2005/02/18 21:52:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -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 c73ebb02b03..f1bbfa2cdac 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -21,7 +21,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.32 2004/12/31 22:03:46 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.33 2005/02/18 21:52:34 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -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(). |