Skip to content

Commit 75fee45

Browse files
committed
Back out use of palloc0 in place if palloc/MemSet. Seems constant len
to MemSet is a performance boost.
1 parent 5d283d8 commit 75fee45

File tree

38 files changed

+212
-110
lines changed

38 files changed

+212
-110
lines changed

contrib/dblink/dblink.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,8 @@ init_dblink_results(MemoryContext fn_mcxt)
14421442

14431443
oldcontext = MemoryContextSwitchTo(fn_mcxt);
14441444

1445-
retval = (dblink_results *) palloc0(sizeof(dblink_results));
1445+
retval = (dblink_results *) palloc(sizeof(dblink_results));
1446+
MemSet(retval, 0, sizeof(dblink_results));
14461447

14471448
retval->tup_num = -1;
14481449
retval->res_id_index = -1;

contrib/intarray/_int.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,10 @@ new_intArrayType(int num)
916916
ArrayType *r;
917917
int nbytes = ARR_OVERHEAD(NDIM) + sizeof(int) * num;
918918

919-
r = (ArrayType *) palloc0(nbytes);
919+
r = (ArrayType *) palloc(nbytes);
920920

921+
MemSet(r, 0, nbytes);
922+
921923
ARR_SIZE(r) = nbytes;
922924
ARR_NDIM(r) = NDIM;
923925
ARR_ELEMTYPE(r) = INT4OID;

src/backend/access/common/indextuple.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.61 2002/11/10 07:25:13 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.62 2002/11/11 03:02:18 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -121,8 +121,9 @@ index_formtuple(TupleDesc tupleDescriptor,
121121
#endif
122122
size = MAXALIGN(size); /* be conservative */
123123

124-
tp = (char *) palloc0(size);
124+
tp = (char *) palloc(size);
125125
tuple = (IndexTuple) tp;
126+
MemSet(tp, 0, size);
126127

127128
DataFill((char *) tp + hoff,
128129
tupleDescriptor,

src/backend/access/common/tupdesc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.92 2002/11/10 07:25:13 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.93 2002/11/11 03:02:18 momjian Exp $
1212
*
1313
* NOTES
1414
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -60,7 +60,8 @@ CreateTemplateTupleDesc(int natts, bool hasoid)
6060
{
6161
uint32 size = natts * sizeof(Form_pg_attribute);
6262

63-
desc->attrs = (Form_pg_attribute *) palloc0(size);
63+
desc->attrs = (Form_pg_attribute *) palloc(size);
64+
MemSet(desc->attrs, 0, size);
6465
}
6566
else
6667
desc->attrs = NULL;

src/backend/access/gist/gist.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.97 2002/11/10 07:25:13 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.98 2002/11/11 03:02:18 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1316,8 +1316,10 @@ gistSplit(Relation r,
13161316
*/
13171317
if (r->rd_att->natts > 1)
13181318
{
1319-
v.spl_idgrp = (int *) palloc0(sizeof(int) * (*len + 1));
1320-
v.spl_grpflag = (char *) palloc0(sizeof(char) * (*len + 1));
1319+
v.spl_idgrp = (int *) palloc(sizeof(int) * (*len + 1));
1320+
MemSet((void *) v.spl_idgrp, 0, sizeof(int) * (*len + 1));
1321+
v.spl_grpflag = (char *) palloc(sizeof(char) * (*len + 1));
1322+
MemSet((void *) v.spl_grpflag, 0, sizeof(char) * (*len + 1));
13211323
v.spl_ngrp = (int *) palloc(sizeof(int) * (*len + 1));
13221324

13231325
MaxGrpId = gistfindgroup(giststate, (GISTENTRY *) VARDATA(entryvec), &v);

src/backend/access/nbtree/nbtsort.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* Portions Copyright (c) 1994, Regents of the University of California
3636
*
3737
* IDENTIFICATION
38-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.67 2002/11/10 07:25:13 momjian Exp $
38+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.68 2002/11/11 03:02:18 momjian Exp $
3939
*
4040
*-------------------------------------------------------------------------
4141
*/
@@ -111,7 +111,9 @@ static void _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2);
111111
BTSpool *
112112
_bt_spoolinit(Relation index, bool isunique)
113113
{
114-
BTSpool *btspool = (BTSpool *) palloc0(sizeof(BTSpool));
114+
BTSpool *btspool = (BTSpool *) palloc(sizeof(BTSpool));
115+
116+
MemSet((char *) btspool, 0, sizeof(BTSpool));
115117

116118
btspool->index = index;
117119
btspool->isunique = isunique;
@@ -205,7 +207,9 @@ _bt_blnewpage(Relation index, Buffer *buf, Page *page, int flags)
205207
static BTPageState *
206208
_bt_pagestate(Relation index, int flags, int level)
207209
{
208-
BTPageState *state = (BTPageState *) palloc0(sizeof(BTPageState));
210+
BTPageState *state = (BTPageState *) palloc(sizeof(BTPageState));
211+
212+
MemSet((char *) state, 0, sizeof(BTPageState));
209213

210214
/* create initial page */
211215
_bt_blnewpage(index, &(state->btps_buf), &(state->btps_page), flags);

src/backend/access/rtree/rtproc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.34 2002/11/10 07:25:13 momjian Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.35 2002/11/11 03:02:18 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -103,7 +103,9 @@ rt_poly_union(PG_FUNCTION_ARGS)
103103
POLYGON *b = PG_GETARG_POLYGON_P(1);
104104
POLYGON *p;
105105

106-
p = (POLYGON *) palloc0(sizeof(POLYGON)); /* zero any holes */
106+
p = (POLYGON *) palloc(sizeof(POLYGON));
107+
108+
MemSet((char *) p, 0, sizeof(POLYGON)); /* zero any holes */
107109
p->size = sizeof(POLYGON);
108110
p->npts = 0;
109111
p->boundbox.high.x = Max(a->boundbox.high.x, b->boundbox.high.x);
@@ -125,7 +127,9 @@ rt_poly_inter(PG_FUNCTION_ARGS)
125127
POLYGON *b = PG_GETARG_POLYGON_P(1);
126128
POLYGON *p;
127129

128-
p = (POLYGON *) palloc0(sizeof(POLYGON)); /* zero any holes */
130+
p = (POLYGON *) palloc(sizeof(POLYGON));
131+
132+
MemSet((char *) p, 0, sizeof(POLYGON)); /* zero any holes */
129133
p->size = sizeof(POLYGON);
130134
p->npts = 0;
131135
p->boundbox.high.x = Min(a->boundbox.high.x, b->boundbox.high.x);

src/backend/catalog/index.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.203 2002/11/10 07:25:13 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.204 2002/11/11 03:02:18 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -112,7 +112,8 @@ BuildFuncTupleDesc(Oid funcOid,
112112
* Allocate and zero a tuple descriptor for a one-column tuple.
113113
*/
114114
funcTupDesc = CreateTemplateTupleDesc(1, false);
115-
funcTupDesc->attrs[0] = (Form_pg_attribute) palloc0(ATTRIBUTE_TUPLE_SIZE);
115+
funcTupDesc->attrs[0] = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
116+
MemSet(funcTupDesc->attrs[0], 0, ATTRIBUTE_TUPLE_SIZE);
116117

117118
/*
118119
* Lookup the function to get its name and return type.

src/backend/commands/analyze.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.48 2002/11/10 07:25:13 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.49 2002/11/11 03:02:18 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -423,7 +423,8 @@ examine_attribute(Relation onerel, int attnum)
423423
* If we have "=" then we're at least able to do the minimal
424424
* algorithm, so start filling in a VacAttrStats struct.
425425
*/
426-
stats = (VacAttrStats *) palloc0(sizeof(VacAttrStats));
426+
stats = (VacAttrStats *) palloc(sizeof(VacAttrStats));
427+
MemSet(stats, 0, sizeof(VacAttrStats));
427428
stats->attnum = attnum;
428429
stats->attr = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
429430
memcpy(stats->attr, attr, ATTRIBUTE_TUPLE_SIZE);

src/backend/commands/copy.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.178 2002/11/10 07:25:13 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.179 2002/11/11 03:02:18 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -804,8 +804,9 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
804804
elements = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
805805
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
806806
defexprs = (Node **) palloc(num_phys_attrs * sizeof(Node *));
807-
constraintexprs = (Node **) palloc0(num_phys_attrs * sizeof(Node *));
807+
constraintexprs = (Node **) palloc(num_phys_attrs * sizeof(Node *));
808808
constraintconsts = (Const **) palloc(num_phys_attrs * sizeof(Const *));
809+
MemSet(constraintexprs, 0, num_phys_attrs * sizeof(Node *));
809810

810811
for (i = 0; i < num_phys_attrs; i++)
811812
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy