Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78822b3

Browse files
committed
Add palloc0 function to inline MemSet for newNode call.
1 parent7aeab94 commit78822b3

File tree

4 files changed

+49
-20
lines changed

4 files changed

+49
-20
lines changed

‎src/backend/nodes/nodes.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/nodes/nodes.c,v 1.17 2002/10/11 04:16:44 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/nodes/nodes.c,v 1.18 2002/11/10 02:17:25 momjian Exp $
1313
*
1414
* HISTORY
1515
* Andrew YuOct 20, 1994file creation
@@ -28,15 +28,5 @@
2828
* macro makeNode. eg. to create a Resdom node, use makeNode(Resdom)
2929
*
3030
*/
31-
Node*
32-
newNode(Sizesize,NodeTagtag)
33-
{
34-
Node*newNode;
31+
Node*newNodeMacroHolder;
3532

36-
Assert(size >=sizeof(Node));/* need the tag, at least */
37-
38-
newNode= (Node*)palloc(size);
39-
MemSet((char*)newNode,0,size);
40-
newNode->type=tag;
41-
returnnewNode;
42-
}

‎src/backend/utils/mmgr/mcxt.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.34 2002/10/11 04:16:44 momjian Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.35 2002/11/10 02:17:25 momjian Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -452,6 +452,29 @@ MemoryContextAlloc(MemoryContext context, Size size)
452452
return (*context->methods->alloc) (context,size);
453453
}
454454

455+
/*
456+
* MemoryContextAllocZero
457+
*Like MemoryContextAlloc, but clears allocated memory
458+
*
459+
*We could just call MemoryContextAlloc then clear the memory, but this
460+
*function is called too many times, so we have a separate version.
461+
*/
462+
void*
463+
MemoryContextAllocZero(MemoryContextcontext,Sizesize)
464+
{
465+
void*ret;
466+
467+
AssertArg(MemoryContextIsValid(context));
468+
469+
if (!AllocSizeIsValid(size))
470+
elog(ERROR,"MemoryContextAllocZero: invalid request size %lu",
471+
(unsigned long)size);
472+
473+
ret= (*context->methods->alloc) (context,size);
474+
MemSet(ret,0,size);
475+
returnret;
476+
}
477+
455478
/*
456479
* pfree
457480
*Release an allocated chunk.

‎src/include/nodes/nodes.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: nodes.h,v 1.121 2002/11/06 00:00:44 tgl Exp $
10+
* $Id: nodes.h,v 1.122 2002/11/10 02:17:25 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -262,6 +262,24 @@ typedef struct Node
262262

263263
#definenodeTag(nodeptr)(((Node*)(nodeptr))->type)
264264

265+
/*
266+
*There is no way to dereference the palloc'ed pointer to assign the
267+
*tag, and return the pointer itself, so we need a holder variable.
268+
*Fortunately, this function isn't recursive so we just define
269+
*a global variable for this purpose.
270+
*/
271+
externNode*newNodeMacroHolder;
272+
273+
#definenewNode(size,tag) \
274+
( \
275+
AssertMacro((size) >= sizeof(Node)),/* need the tag, at least */ \
276+
\
277+
newNodeMacroHolder = (Node *) palloc0(size), \
278+
newNodeMacroHolder->type = (tag), \
279+
newNodeMacroHolder \
280+
)
281+
282+
265283
#definemakeNode(_type_)((_type_ *) newNode(sizeof(_type_),T_##_type_))
266284
#defineNodeSetTag(nodeptr,t)(((Node*)(nodeptr))->type = (t))
267285

@@ -283,11 +301,6 @@ typedef struct Node
283301
* ----------------------------------------------------------------
284302
*/
285303

286-
/*
287-
* nodes/nodes.c
288-
*/
289-
externNode*newNode(Sizesize,NodeTagtag);
290-
291304
/*
292305
* nodes/{outfuncs.c,print.c}
293306
*/

‎src/include/utils/palloc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
2222
* Portions Copyright (c) 1994, Regents of the University of California
2323
*
24-
* $Id: palloc.h,v 1.21 2002/10/11 04:16:44 momjian Exp $
24+
* $Id: palloc.h,v 1.22 2002/11/10 02:17:25 momjian Exp $
2525
*
2626
*-------------------------------------------------------------------------
2727
*/
@@ -46,9 +46,12 @@ extern DLLIMPORT MemoryContext CurrentMemoryContext;
4646
* Fundamental memory-allocation operations (more are in utils/memutils.h)
4747
*/
4848
externvoid*MemoryContextAlloc(MemoryContextcontext,Sizesize);
49+
externvoid*MemoryContextAllocZero(MemoryContextcontext,Sizesize);
4950

5051
#definepalloc(sz)MemoryContextAlloc(CurrentMemoryContext, (sz))
5152

53+
#definepalloc0(sz)MemoryContextAllocZero(CurrentMemoryContext, (sz))
54+
5255
externvoidpfree(void*pointer);
5356

5457
externvoid*repalloc(void*pointer,Sizesize);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp