Skip to content

Commit 8fee961

Browse files
committed
Merge palloc()/MemSet(0) calls into a single palloc0() call.
1 parent 78822b3 commit 8fee961

37 files changed

+107
-210
lines changed

contrib/dblink/dblink.c

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

14431443
oldcontext = MemoryContextSwitchTo(fn_mcxt);
14441444

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

14481447
retval->tup_num = -1;
14491448
retval->res_id_index = -1;

contrib/intarray/_int.c

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

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

921-
MemSet(r, 0, nbytes);
922-
923921
ARR_SIZE(r) = nbytes;
924922
ARR_NDIM(r) = NDIM;
925923
ARR_ELEMTYPE(r) = INT4OID;

src/backend/access/common/indextuple.c

Lines changed: 2 additions & 3 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.60 2002/09/04 20:31:08 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.61 2002/11/10 07:25:13 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -121,9 +121,8 @@ index_formtuple(TupleDesc tupleDescriptor,
121121
#endif
122122
size = MAXALIGN(size); /* be conservative */
123123

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

128127
DataFill((char *) tp + hoff,
129128
tupleDescriptor,

src/backend/access/common/tupdesc.c

Lines changed: 2 additions & 3 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.91 2002/09/28 20:00:18 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.92 2002/11/10 07:25:13 momjian Exp $
1212
*
1313
* NOTES
1414
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -60,8 +60,7 @@ CreateTemplateTupleDesc(int natts, bool hasoid)
6060
{
6161
uint32 size = natts * sizeof(Form_pg_attribute);
6262

63-
desc->attrs = (Form_pg_attribute *) palloc(size);
64-
MemSet(desc->attrs, 0, size);
63+
desc->attrs = (Form_pg_attribute *) palloc0(size);
6564
}
6665
else
6766
desc->attrs = NULL;

src/backend/access/gist/gist.c

Lines changed: 3 additions & 5 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.96 2002/09/04 20:31:09 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.97 2002/11/10 07:25:13 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1316,10 +1316,8 @@ gistSplit(Relation r,
13161316
*/
13171317
if (r->rd_att->natts > 1)
13181318
{
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));
1319+
v.spl_idgrp = (int *) palloc0(sizeof(int) * (*len + 1));
1320+
v.spl_grpflag = (char *) palloc0(sizeof(char) * (*len + 1));
13231321
v.spl_ngrp = (int *) palloc(sizeof(int) * (*len + 1));
13241322

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

src/backend/access/nbtree/nbtsort.c

Lines changed: 3 additions & 7 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.66 2002/08/06 19:41:23 tgl Exp $
38+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.67 2002/11/10 07:25:13 momjian Exp $
3939
*
4040
*-------------------------------------------------------------------------
4141
*/
@@ -111,9 +111,7 @@ static void _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2);
111111
BTSpool *
112112
_bt_spoolinit(Relation index, bool isunique)
113113
{
114-
BTSpool *btspool = (BTSpool *) palloc(sizeof(BTSpool));
115-
116-
MemSet((char *) btspool, 0, sizeof(BTSpool));
114+
BTSpool *btspool = (BTSpool *) palloc0(sizeof(BTSpool));
117115

118116
btspool->index = index;
119117
btspool->isunique = isunique;
@@ -207,9 +205,7 @@ _bt_blnewpage(Relation index, Buffer *buf, Page *page, int flags)
207205
static BTPageState *
208206
_bt_pagestate(Relation index, int flags, int level)
209207
{
210-
BTPageState *state = (BTPageState *) palloc(sizeof(BTPageState));
211-
212-
MemSet((char *) state, 0, sizeof(BTPageState));
208+
BTPageState *state = (BTPageState *) palloc0(sizeof(BTPageState));
213209

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

src/backend/access/rtree/rtproc.c

Lines changed: 3 additions & 7 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.33 2002/06/20 20:29:25 momjian Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.34 2002/11/10 07:25:13 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -103,9 +103,7 @@ rt_poly_union(PG_FUNCTION_ARGS)
103103
POLYGON *b = PG_GETARG_POLYGON_P(1);
104104
POLYGON *p;
105105

106-
p = (POLYGON *) palloc(sizeof(POLYGON));
107-
108-
MemSet((char *) p, 0, sizeof(POLYGON)); /* zero any holes */
106+
p = (POLYGON *) palloc0(sizeof(POLYGON)); /* zero any holes */
109107
p->size = sizeof(POLYGON);
110108
p->npts = 0;
111109
p->boundbox.high.x = Max(a->boundbox.high.x, b->boundbox.high.x);
@@ -127,9 +125,7 @@ rt_poly_inter(PG_FUNCTION_ARGS)
127125
POLYGON *b = PG_GETARG_POLYGON_P(1);
128126
POLYGON *p;
129127

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

src/backend/catalog/index.c

Lines changed: 2 additions & 3 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.202 2002/10/21 22:06:19 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.203 2002/11/10 07:25:13 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -112,8 +112,7 @@ 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) palloc(ATTRIBUTE_TUPLE_SIZE);
116-
MemSet(funcTupDesc->attrs[0], 0, ATTRIBUTE_TUPLE_SIZE);
115+
funcTupDesc->attrs[0] = (Form_pg_attribute) palloc0(ATTRIBUTE_TUPLE_SIZE);
117116

118117
/*
119118
* Lookup the function to get its name and return type.

src/backend/commands/analyze.c

Lines changed: 2 additions & 3 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.47 2002/09/23 20:43:40 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.48 2002/11/10 07:25:13 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -423,8 +423,7 @@ 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 *) palloc(sizeof(VacAttrStats));
427-
MemSet(stats, 0, sizeof(VacAttrStats));
426+
stats = (VacAttrStats *) palloc0(sizeof(VacAttrStats));
428427
stats->attnum = attnum;
429428
stats->attr = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
430429
memcpy(stats->attr, attr, ATTRIBUTE_TUPLE_SIZE);

src/backend/commands/copy.c

Lines changed: 2 additions & 3 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.177 2002/10/19 00:25:36 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.178 2002/11/10 07:25:13 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -804,9 +804,8 @@ 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 **) palloc(num_phys_attrs * sizeof(Node *));
807+
constraintexprs = (Node **) palloc0(num_phys_attrs * sizeof(Node *));
808808
constraintconsts = (Const **) palloc(num_phys_attrs * sizeof(Const *));
809-
MemSet(constraintexprs, 0, num_phys_attrs * sizeof(Node *));
810809

811810
for (i = 0; i < num_phys_attrs; i++)
812811
{

src/backend/commands/explain.c

Lines changed: 2 additions & 3 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.90 2002/11/06 00:00:43 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.91 2002/11/10 07:25:13 momjian Exp $
99
*
1010
*/
1111

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

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

170169
es->printCost = true; /* default */
171170

src/backend/commands/opclasscmds.c

Lines changed: 4 additions & 7 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.6 2002/10/04 22:19:29 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.7 2002/11/10 07:25:13 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -124,12 +124,9 @@ DefineOpClass(CreateOpClassStmt *stmt)
124124
* do this mainly so that we can detect duplicate strategy numbers and
125125
* support-proc numbers.
126126
*/
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);
127+
operators = (Oid *) palloc0(sizeof(Oid) * numOperators);
128+
procedures = (Oid *) palloc0(sizeof(Oid) * numProcs);
129+
recheck = (bool *) palloc0(sizeof(bool) * numOperators);
133130

134131
/*
135132
* Scan the "items" list to obtain additional info.

src/backend/commands/prepare.c

Lines changed: 2 additions & 3 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.4 2002/09/20 03:45:08 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.5 2002/11/10 07:25:13 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -116,8 +116,7 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest)
116116
if (nargs != length(stmt->params))
117117
elog(ERROR, "ExecuteQuery: wrong number of arguments");
118118

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

122121
foreach(l, stmt->params)
123122
{

src/backend/commands/trigger.c

Lines changed: 7 additions & 22 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.136 2002/10/21 19:55:49 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.137 2002/11/10 07:25:13 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,8 +779,7 @@ RelationBuildTriggers(Relation relation)
779779
RelationGetRelationName(relation));
780780

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

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

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

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

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

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

12921279
LocTriggerData.type = T_TriggerData;
12931280
LocTriggerData.tg_event = TRIGGER_EVENT_UPDATE | TRIGGER_EVENT_ROW | TRIGGER_EVENT_BEFORE;
@@ -1769,9 +1756,7 @@ deferredTriggerInvokeEvents(bool immediate_only)
17691756
* Allocate space to cache fmgr lookup info for triggers.
17701757
*/
17711758
finfo = (FmgrInfo *)
1772-
palloc(trigdesc->numtriggers * sizeof(FmgrInfo));
1773-
MemSet(finfo, 0,
1774-
trigdesc->numtriggers * sizeof(FmgrInfo));
1759+
palloc0(trigdesc->numtriggers * sizeof(FmgrInfo));
17751760
}
17761761

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

src/backend/commands/vacuumlazy.c

Lines changed: 2 additions & 3 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.20 2002/09/20 19:56:01 tgl Exp $
34+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuumlazy.c,v 1.21 2002/11/10 07:25:13 momjian Exp $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -147,8 +147,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
147147
vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared,
148148
&OldestXmin, &FreezeLimit);
149149

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

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

0 commit comments

Comments
 (0)