mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
Back out use of palloc0 in place if palloc/MemSet. Seems constant len
to MemSet is a performance boost.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.81 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.82 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -248,7 +248,8 @@ makeacl(int n)
|
||||
if (n < 0)
|
||||
elog(ERROR, "makeacl: invalid size: %d", n);
|
||||
size = ACL_N_SIZE(n);
|
||||
new_acl = (Acl *) palloc0(size);
|
||||
new_acl = (Acl *) palloc(size);
|
||||
MemSet((char *) new_acl, 0, size);
|
||||
new_acl->size = size;
|
||||
new_acl->ndim = 1;
|
||||
new_acl->flags = 0;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.83 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.84 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -235,7 +235,8 @@ array_in(PG_FUNCTION_ARGS)
|
||||
if (nitems == 0)
|
||||
{
|
||||
/* Return empty array */
|
||||
retval = (ArrayType *) palloc0(sizeof(ArrayType));
|
||||
retval = (ArrayType *) palloc(sizeof(ArrayType));
|
||||
MemSet(retval, 0, sizeof(ArrayType));
|
||||
retval->size = sizeof(ArrayType);
|
||||
retval->elemtype = element_type;
|
||||
PG_RETURN_ARRAYTYPE_P(retval);
|
||||
@@ -248,7 +249,8 @@ array_in(PG_FUNCTION_ARGS)
|
||||
typmod, typdelim, typlen, typbyval, typalign,
|
||||
&nbytes);
|
||||
nbytes += ARR_OVERHEAD(ndim);
|
||||
retval = (ArrayType *) palloc0(nbytes);
|
||||
retval = (ArrayType *) palloc(nbytes);
|
||||
MemSet(retval, 0, nbytes);
|
||||
retval->size = nbytes;
|
||||
retval->ndim = ndim;
|
||||
retval->elemtype = element_type;
|
||||
@@ -395,7 +397,8 @@ ReadArrayStr(char *arrayStr,
|
||||
prod[MAXDIM];
|
||||
|
||||
mda_get_prod(ndim, dim, prod);
|
||||
values = (Datum *) palloc0(nitems * sizeof(Datum));
|
||||
values = (Datum *) palloc(nitems * sizeof(Datum));
|
||||
MemSet(values, 0, nitems * sizeof(Datum));
|
||||
MemSet(indx, 0, sizeof(indx));
|
||||
|
||||
/* read array enclosed within {} */
|
||||
@@ -511,7 +514,10 @@ ReadArrayStr(char *arrayStr,
|
||||
if (!typbyval)
|
||||
for (i = 0; i < nitems; i++)
|
||||
if (values[i] == (Datum) 0)
|
||||
values[i] = PointerGetDatum(palloc0(typlen));
|
||||
{
|
||||
values[i] = PointerGetDatum(palloc(typlen));
|
||||
MemSet(DatumGetPointer(values[i]), 0, typlen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1587,7 +1593,8 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType)
|
||||
|
||||
/* Allocate and initialize the result array */
|
||||
nbytes += ARR_OVERHEAD(ndim);
|
||||
result = (ArrayType *) palloc0(nbytes);
|
||||
result = (ArrayType *) palloc(nbytes);
|
||||
MemSet(result, 0, nbytes);
|
||||
|
||||
result->size = nbytes;
|
||||
result->ndim = ndim;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.69 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.70 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -3130,8 +3130,9 @@ poly_in(PG_FUNCTION_ARGS)
|
||||
elog(ERROR, "Bad polygon external representation '%s'", str);
|
||||
|
||||
size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts;
|
||||
poly = (POLYGON *) palloc0(size); /* zero any holes */
|
||||
poly = (POLYGON *) palloc(size);
|
||||
|
||||
MemSet((char *) poly, 0, size); /* zero any holes */
|
||||
poly->size = size;
|
||||
poly->npts = npts;
|
||||
|
||||
@@ -4451,7 +4452,9 @@ circle_poly(PG_FUNCTION_ARGS)
|
||||
if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)
|
||||
elog(ERROR, "too many points requested");
|
||||
|
||||
poly = (POLYGON *) palloc0(size); /* zero any holes */
|
||||
poly = (POLYGON *) palloc(size);
|
||||
|
||||
MemSet(poly, 0, size); /* zero any holes */
|
||||
poly->size = size;
|
||||
poly->npts = npts;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* is for IP V4 CIDR notation, but prepared for V6: just
|
||||
* add the necessary bits where the comments indicate.
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.36 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.37 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
* Jon Postel RIP 16 Oct 1998
|
||||
*/
|
||||
@@ -51,8 +51,9 @@ network_in(char *src, int type)
|
||||
int bits;
|
||||
inet *dst;
|
||||
|
||||
dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
|
||||
/* make sure any unused bits in a CIDR value are zeroed */
|
||||
dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
|
||||
MemSet(dst, 0, VARHDRSZ + sizeof(inet_struct));
|
||||
|
||||
/* First, try for an IP V4 address: */
|
||||
ip_family(dst) = AF_INET;
|
||||
@@ -493,8 +494,9 @@ network_broadcast(PG_FUNCTION_ARGS)
|
||||
inet *ip = PG_GETARG_INET_P(0);
|
||||
inet *dst;
|
||||
|
||||
dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
|
||||
/* make sure any unused bits are zeroed */
|
||||
dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
|
||||
MemSet(dst, 0, VARHDRSZ + sizeof(inet_struct));
|
||||
|
||||
if (ip_family(ip) == AF_INET)
|
||||
{
|
||||
@@ -532,8 +534,9 @@ network_network(PG_FUNCTION_ARGS)
|
||||
inet *ip = PG_GETARG_INET_P(0);
|
||||
inet *dst;
|
||||
|
||||
dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
|
||||
/* make sure any unused bits are zeroed */
|
||||
dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
|
||||
MemSet(dst, 0, VARHDRSZ + sizeof(inet_struct));
|
||||
|
||||
if (ip_family(ip) == AF_INET)
|
||||
{
|
||||
@@ -571,8 +574,9 @@ network_netmask(PG_FUNCTION_ARGS)
|
||||
inet *ip = PG_GETARG_INET_P(0);
|
||||
inet *dst;
|
||||
|
||||
dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
|
||||
/* make sure any unused bits are zeroed */
|
||||
dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
|
||||
MemSet(dst, 0, VARHDRSZ + sizeof(inet_struct));
|
||||
|
||||
if (ip_family(ip) == AF_INET)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.27 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.28 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -107,8 +107,9 @@ bit_in(PG_FUNCTION_ARGS)
|
||||
bitlen, atttypmod);
|
||||
|
||||
len = VARBITTOTALLEN(atttypmod);
|
||||
result = (VarBit *) palloc(len);
|
||||
/* set to 0 so that *r is always initialised and string is zero-padded */
|
||||
result = (VarBit *) palloc0(len);
|
||||
MemSet(result, 0, len);
|
||||
VARATT_SIZEP(result) = len;
|
||||
VARBITLEN(result) = atttypmod;
|
||||
|
||||
@@ -231,8 +232,9 @@ bit(PG_FUNCTION_ARGS)
|
||||
VARBITLEN(arg), len);
|
||||
|
||||
rlen = VARBITTOTALLEN(len);
|
||||
result = (VarBit *) palloc(rlen);
|
||||
/* set to 0 so that string is zero-padded */
|
||||
result = (VarBit *) palloc0(rlen);
|
||||
MemSet(result, 0, rlen);
|
||||
VARATT_SIZEP(result) = rlen;
|
||||
VARBITLEN(result) = len;
|
||||
|
||||
@@ -314,8 +316,9 @@ varbit_in(PG_FUNCTION_ARGS)
|
||||
atttypmod);
|
||||
|
||||
len = VARBITTOTALLEN(bitlen);
|
||||
result = (VarBit *) palloc(len);
|
||||
/* set to 0 so that *r is always initialised and string is zero-padded */
|
||||
result = (VarBit *) palloc0(len);
|
||||
MemSet(result, 0, len);
|
||||
VARATT_SIZEP(result) = len;
|
||||
VARBITLEN(result) = Min(bitlen, atttypmod);
|
||||
|
||||
|
||||
5
src/backend/utils/cache/catcache.c
vendored
5
src/backend/utils/cache/catcache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.100 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.101 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -808,7 +808,8 @@ InitCatCache(int id,
|
||||
*
|
||||
* Note: we assume zeroing initializes the Dllist headers correctly
|
||||
*/
|
||||
cp = (CatCache *) palloc0(sizeof(CatCache) + NCCBUCKETS * sizeof(Dllist));
|
||||
cp = (CatCache *) palloc(sizeof(CatCache) + NCCBUCKETS * sizeof(Dllist));
|
||||
MemSet((char *) cp, 0, sizeof(CatCache) + NCCBUCKETS * sizeof(Dllist));
|
||||
|
||||
/*
|
||||
* initialize the cache's relation information for the relation
|
||||
|
||||
17
src/backend/utils/cache/relcache.c
vendored
17
src/backend/utils/cache/relcache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.178 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.179 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1348,9 +1348,13 @@ formrdesc(const char *relationName,
|
||||
|
||||
/*
|
||||
* allocate new relation desc
|
||||
*/
|
||||
relation = (Relation) palloc(sizeof(RelationData));
|
||||
|
||||
/*
|
||||
* clear all fields of reldesc
|
||||
*/
|
||||
relation = (Relation) palloc0(sizeof(RelationData));
|
||||
MemSet((char *) relation, 0, sizeof(RelationData));
|
||||
relation->rd_targblock = InvalidBlockNumber;
|
||||
|
||||
/* make sure relation is marked as having no open file yet */
|
||||
@@ -1376,7 +1380,8 @@ formrdesc(const char *relationName,
|
||||
* get us launched. RelationCacheInitializePhase2() will read the
|
||||
* real data from pg_class and replace what we've done here.
|
||||
*/
|
||||
relation->rd_rel = (Form_pg_class) palloc0(CLASS_TUPLE_SIZE);
|
||||
relation->rd_rel = (Form_pg_class) palloc(CLASS_TUPLE_SIZE);
|
||||
MemSet(relation->rd_rel, 0, CLASS_TUPLE_SIZE);
|
||||
|
||||
namestrcpy(&relation->rd_rel->relname, relationName);
|
||||
relation->rd_rel->relnamespace = PG_CATALOG_NAMESPACE;
|
||||
@@ -2049,7 +2054,8 @@ RelationBuildLocalRelation(const char *relname,
|
||||
/*
|
||||
* allocate a new relation descriptor and fill in basic state fields.
|
||||
*/
|
||||
rel = (Relation) palloc0(sizeof(RelationData));
|
||||
rel = (Relation) palloc(sizeof(RelationData));
|
||||
MemSet((char *) rel, 0, sizeof(RelationData));
|
||||
|
||||
rel->rd_targblock = InvalidBlockNumber;
|
||||
|
||||
@@ -2087,7 +2093,8 @@ RelationBuildLocalRelation(const char *relname,
|
||||
/*
|
||||
* initialize relation tuple form (caller may add/override data later)
|
||||
*/
|
||||
rel->rd_rel = (Form_pg_class) palloc0(CLASS_TUPLE_SIZE);
|
||||
rel->rd_rel = (Form_pg_class) palloc(CLASS_TUPLE_SIZE);
|
||||
MemSet((char *) rel->rd_rel, 0, CLASS_TUPLE_SIZE);
|
||||
|
||||
namestrcpy(&rel->rd_rel->relname, relname);
|
||||
rel->rd_rel->relnamespace = relnamespace;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.64 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.65 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1550,8 +1550,9 @@ Int64GetDatum(int64 X)
|
||||
* with zeroes in the unused bits. This is needed so that, for
|
||||
* example, hash join of int8 will behave properly.
|
||||
*/
|
||||
int64 *retval = (int64 *) palloc0(Max(sizeof(int64), 8));
|
||||
int64 *retval = (int64 *) palloc(Max(sizeof(int64), 8));
|
||||
|
||||
MemSet(retval, 0, Max(sizeof(int64), 8));
|
||||
*retval = X;
|
||||
return PointerGetDatum(retval);
|
||||
#endif /* INT64_IS_BUSTED */
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.30 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.31 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -414,7 +414,9 @@ tuplesort_begin_common(bool randomAccess)
|
||||
{
|
||||
Tuplesortstate *state;
|
||||
|
||||
state = (Tuplesortstate *) palloc0(sizeof(Tuplesortstate));
|
||||
state = (Tuplesortstate *) palloc(sizeof(Tuplesortstate));
|
||||
|
||||
MemSet((char *) state, 0, sizeof(Tuplesortstate));
|
||||
|
||||
state->status = TSS_INITIAL;
|
||||
state->randomAccess = randomAccess;
|
||||
@@ -457,9 +459,11 @@ tuplesort_begin_heap(TupleDesc tupDesc,
|
||||
|
||||
state->tupDesc = tupDesc;
|
||||
state->nKeys = nkeys;
|
||||
state->scanKeys = (ScanKey) palloc0(nkeys * sizeof(ScanKeyData));
|
||||
state->scanKeys = (ScanKey) palloc(nkeys * sizeof(ScanKeyData));
|
||||
MemSet(state->scanKeys, 0, nkeys * sizeof(ScanKeyData));
|
||||
state->sortFnKinds = (SortFunctionKind *)
|
||||
palloc0(nkeys * sizeof(SortFunctionKind));
|
||||
palloc(nkeys * sizeof(SortFunctionKind));
|
||||
MemSet(state->sortFnKinds, 0, nkeys * sizeof(SortFunctionKind));
|
||||
|
||||
for (i = 0; i < nkeys; i++)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplestore.c,v 1.8 2002/11/10 07:25:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplestore.c,v 1.9 2002/11/11 03:02:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -197,7 +197,9 @@ tuplestore_begin_common(bool randomAccess, int maxKBytes)
|
||||
{
|
||||
Tuplestorestate *state;
|
||||
|
||||
state = (Tuplestorestate *) palloc0(sizeof(Tuplestorestate));
|
||||
state = (Tuplestorestate *) palloc(sizeof(Tuplestorestate));
|
||||
|
||||
MemSet((char *) state, 0, sizeof(Tuplestorestate));
|
||||
|
||||
state->status = TSS_INITIAL;
|
||||
state->randomAccess = randomAccess;
|
||||
|
||||
Reference in New Issue
Block a user