1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +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:
Bruce Momjian
2002-11-11 03:02:20 +00:00
parent 5d283d89cb
commit 75fee4535d
38 changed files with 212 additions and 110 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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)
{

View File

@@ -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);