*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
/*
* 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)
{
return old;
}
+#endif /* ! __GNUC__ */
+
/*
* MemoryContextStrdup
* Like strdup(), but allocate from the specified context
* 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 $
*
*-------------------------------------------------------------------------
*/
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().