diff options
| author | Tom Lane | 2014-11-28 18:37:25 +0000 |
|---|---|---|
| committer | Tom Lane | 2014-11-28 18:37:25 +0000 |
| commit | f4e031c662a6b600b786c4849968a099c58fcce7 (patch) | |
| tree | 6a082f889ff2ea5b64bb43c467760686e5f013b0 /src/pl | |
| parent | 96d66bcfc60d9bcb7db767f23d33abf4d8bc7021 (diff) | |
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
Diffstat (limited to 'src/pl')
| -rw-r--r-- | src/pl/plpgsql/src/pl_exec.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index 11cb47b522..d1feef78b7 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -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(¶mstr); - 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; } |
