Re: Is it really such a good thing for newNode() to be a macro? - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: Is it really such a good thing for newNode() to be a macro?
Date
Msg-id 48B5656D.6010909@enterprisedb.com
Whole thread Raw
In response to Re: Is it really such a good thing for newNode() to be a macro?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Is it really such a good thing for newNode() to be a macro?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane wrote:
> "Heikki Linnakangas" <heikki@enterprisedb.com> writes:
>> Note that the MemSetLoop macro used in palloc0fast is supposed to be 
>> evaluated at compile time,
> 
> Oooh, good point, I had forgotten about that little detail.  Yeah,
> we'll lose that optimization if we move the code out-of-line.

Well, we could still have the MemSetTest outside the function, and 
evaluated at compile-time, if we provided an aligned and unaligned 
version of newNode:

#define newNode(size, tag) \
( \AssertMacro((size) >= sizeof(Node)),        /* need the tag, at least */ \( MemSetTest(0, sz) ? \
newNodeAligned(CurrentMemoryContext,sz, tag) : \    newNodeNotAligned(CurrentMemoryContext, sz, tag))
 

And if you're worried about the function call overhead, 
newNode(Not)Aligned could have the contents of MemoryContextAllocZero 
inlined into it. Not sure how much optimization is worthwhile here..

--   Heikki Linnakangas  EnterpriseDB   http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Benedek László
Date:
Subject: Re: pg_dump roles support
Next
From: Tom Lane
Date:
Subject: Re: Is it really such a good thing for newNode() to be a macro?