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

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
{

src/backend/commands/explain.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994-5, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.91 2002/11/10 07:25:13 momjian Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.92 2002/11/11 03:02:18 momjian Exp $
99
*
1010
*/
1111

@@ -164,7 +164,8 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate)
164164
(double) endtime.tv_usec / 1000000.0;
165165
}
166166

167-
es = (ExplainState *) palloc0(sizeof(ExplainState));
167+
es = (ExplainState *) palloc(sizeof(ExplainState));
168+
MemSet(es, 0, sizeof(ExplainState));
168169

169170
es->printCost = true; /* default */
170171

src/backend/commands/opclasscmds.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.7 2002/11/10 07:25:13 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.8 2002/11/11 03:02:18 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -124,9 +124,12 @@ DefineOpClass(CreateOpClassStmt *stmt)
124124
* do this mainly so that we can detect duplicate strategy numbers and
125125
* support-proc numbers.
126126
*/
127-
operators = (Oid *) palloc0(sizeof(Oid) * numOperators);
128-
procedures = (Oid *) palloc0(sizeof(Oid) * numProcs);
129-
recheck = (bool *) palloc0(sizeof(bool) * numOperators);
127+
operators = (Oid *) palloc(sizeof(Oid) * numOperators);
128+
MemSet(operators, 0, sizeof(Oid) * numOperators);
129+
procedures = (Oid *) palloc(sizeof(Oid) * numProcs);
130+
MemSet(procedures, 0, sizeof(Oid) * numProcs);
131+
recheck = (bool *) palloc(sizeof(bool) * numOperators);
132+
MemSet(recheck, 0, sizeof(bool) * numOperators);
130133

131134
/*
132135
* Scan the "items" list to obtain additional info.

src/backend/commands/prepare.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2002, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.5 2002/11/10 07:25:13 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.6 2002/11/11 03:02:18 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -116,7 +116,8 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest)
116116
if (nargs != length(stmt->params))
117117
elog(ERROR, "ExecuteQuery: wrong number of arguments");
118118

119-
paramLI = (ParamListInfo) palloc0((nargs + 1) * sizeof(ParamListInfoData));
119+
paramLI = (ParamListInfo) palloc((nargs + 1) * sizeof(ParamListInfoData));
120+
MemSet(paramLI, 0, (nargs + 1) * sizeof(ParamListInfoData));
120121

121122
foreach(l, stmt->params)
122123
{

src/backend/commands/trigger.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.137 2002/11/10 07:25:13 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.138 2002/11/11 03:02:18 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -94,7 +94,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
9494
constrrelid = RangeVarGetRelid(stmt->constrrel, false);
9595
else if (stmt->isconstraint)
9696
{
97-
/*
97+
/*
9898
* If this trigger is a constraint (and a foreign key one)
9999
* then we really need a constrrelid. Since we don't have one,
100100
* we'll try to generate one from the argument information.
@@ -779,7 +779,8 @@ RelationBuildTriggers(Relation relation)
779779
RelationGetRelationName(relation));
780780

781781
/* Build trigdesc */
782-
trigdesc = (TriggerDesc *) palloc0(sizeof(TriggerDesc));
782+
trigdesc = (TriggerDesc *) palloc(sizeof(TriggerDesc));
783+
MemSet(trigdesc, 0, sizeof(TriggerDesc));
783784
trigdesc->triggers = triggers;
784785
trigdesc->numtriggers = ntrigs;
785786
for (found = 0; found < ntrigs; found++)
@@ -1145,8 +1146,12 @@ ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo,
11451146

11461147
/* Allocate cache space for fmgr lookup info, if not done yet */
11471148
if (relinfo->ri_TrigFunctions == NULL)
1149+
{
11481150
relinfo->ri_TrigFunctions = (FmgrInfo *)
1149-
palloc0(trigdesc->numtriggers * sizeof(FmgrInfo));
1151+
palloc(trigdesc->numtriggers * sizeof(FmgrInfo));
1152+
MemSet(relinfo->ri_TrigFunctions, 0,
1153+
trigdesc->numtriggers * sizeof(FmgrInfo));
1154+
}
11501155

11511156
LocTriggerData.type = T_TriggerData;
11521157
LocTriggerData.tg_event = TRIGGER_EVENT_INSERT | TRIGGER_EVENT_ROW | TRIGGER_EVENT_BEFORE;
@@ -1201,8 +1206,12 @@ ExecBRDeleteTriggers(EState *estate, ResultRelInfo *relinfo,
12011206

12021207
/* Allocate cache space for fmgr lookup info, if not done yet */
12031208
if (relinfo->ri_TrigFunctions == NULL)
1209+
{
12041210
relinfo->ri_TrigFunctions = (FmgrInfo *)
1205-
palloc0(trigdesc->numtriggers * sizeof(FmgrInfo));
1211+
palloc(trigdesc->numtriggers * sizeof(FmgrInfo));
1212+
MemSet(relinfo->ri_TrigFunctions, 0,
1213+
trigdesc->numtriggers * sizeof(FmgrInfo));
1214+
}
12061215

12071216
LocTriggerData.type = T_TriggerData;
12081217
LocTriggerData.tg_event = TRIGGER_EVENT_DELETE | TRIGGER_EVENT_ROW | TRIGGER_EVENT_BEFORE;
@@ -1273,8 +1282,12 @@ ExecBRUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
12731282

12741283
/* Allocate cache space for fmgr lookup info, if not done yet */
12751284
if (relinfo->ri_TrigFunctions == NULL)
1285+
{
12761286
relinfo->ri_TrigFunctions = (FmgrInfo *)
1277-
palloc0(trigdesc->numtriggers * sizeof(FmgrInfo));
1287+
palloc(trigdesc->numtriggers * sizeof(FmgrInfo));
1288+
MemSet(relinfo->ri_TrigFunctions, 0,
1289+
trigdesc->numtriggers * sizeof(FmgrInfo));
1290+
}
12781291

12791292
LocTriggerData.type = T_TriggerData;
12801293
LocTriggerData.tg_event = TRIGGER_EVENT_UPDATE | TRIGGER_EVENT_ROW | TRIGGER_EVENT_BEFORE;
@@ -1756,7 +1769,9 @@ deferredTriggerInvokeEvents(bool immediate_only)
17561769
* Allocate space to cache fmgr lookup info for triggers.
17571770
*/
17581771
finfo = (FmgrInfo *)
1759-
palloc0(trigdesc->numtriggers * sizeof(FmgrInfo));
1772+
palloc(trigdesc->numtriggers * sizeof(FmgrInfo));
1773+
MemSet(finfo, 0,
1774+
trigdesc->numtriggers * sizeof(FmgrInfo));
17601775
}
17611776

17621777
DeferredTriggerExecute(event, i, rel, trigdesc, finfo,

src/backend/commands/vacuumlazy.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
*
3333
* IDENTIFICATION
34-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuumlazy.c,v 1.21 2002/11/10 07:25:13 momjian Exp $
34+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuumlazy.c,v 1.22 2002/11/11 03:02:18 momjian Exp $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -147,7 +147,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
147147
vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared,
148148
&OldestXmin, &FreezeLimit);
149149

150-
vacrelstats = (LVRelStats *) palloc0(sizeof(LVRelStats));
150+
vacrelstats = (LVRelStats *) palloc(sizeof(LVRelStats));
151+
MemSet(vacrelstats, 0, sizeof(LVRelStats));
151152

152153
/* Open all indexes of the relation */
153154
vac_open_indexes(onerel, &nindexes, &Irel);

0 commit comments

Comments
 (0)