1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Add bms_next_member(), and use it where appropriate.

This patch adds a way of iterating through the members of a bitmapset
nondestructively, unlike the old way with bms_first_member().  While
bms_next_member() is very slightly slower than bms_first_member()
(at least for typical-size bitmapsets), eliminating the need to palloc
and pfree a temporary copy of the target bitmapset is a significant win.
So this method should be preferred in all cases where a temporary copy
would be necessary.

Tom Lane, with suggestions from Dean Rasheed and David Rowley
This commit is contained in:
Tom Lane
2014-11-28 13:37:25 -05:00
parent 96d66bcfc6
commit f4e031c662
13 changed files with 114 additions and 76 deletions

View File

@@ -5263,7 +5263,6 @@ setup_param_list(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
*/
if (!bms_is_empty(expr->paramnos))
{
Bitmapset *tmpset;
int dno;
paramLI = (ParamListInfo)
@@ -5276,8 +5275,8 @@ setup_param_list(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
paramLI->numParams = estate->ndatums;
/* Instantiate values for "safe" parameters of the expression */
tmpset = bms_copy(expr->paramnos);
while ((dno = bms_first_member(tmpset)) >= 0)
dno = -1;
while ((dno = bms_next_member(expr->paramnos, dno)) >= 0)
{
PLpgSQL_datum *datum = estate->datums[dno];
@@ -5292,7 +5291,6 @@ setup_param_list(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
prm->ptype = var->datatype->typoid;
}
}
bms_free(tmpset);
/*
* Set up link to active expr where the hook functions can find it.
@@ -6528,15 +6526,14 @@ format_expr_params(PLpgSQL_execstate *estate,
int paramno;
int dno;
StringInfoData paramstr;
Bitmapset *tmpset;
if (!expr->paramnos)
return NULL;
initStringInfo(&paramstr);
tmpset = bms_copy(expr->paramnos);
paramno = 0;
while ((dno = bms_first_member(tmpset)) >= 0)
dno = -1;
while ((dno = bms_next_member(expr->paramnos, dno)) >= 0)
{
Datum paramdatum;
Oid paramtypeid;
@@ -6572,7 +6569,6 @@ format_expr_params(PLpgSQL_execstate *estate,
paramno++;
}
bms_free(tmpset);
return paramstr.data;
}