mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +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:
@ -184,15 +184,13 @@ _outList(StringInfo str, const List *node)
|
||||
static void
|
||||
_outBitmapset(StringInfo str, const Bitmapset *bms)
|
||||
{
|
||||
Bitmapset *tmpset;
|
||||
int x;
|
||||
|
||||
appendStringInfoChar(str, '(');
|
||||
appendStringInfoChar(str, 'b');
|
||||
tmpset = bms_copy(bms);
|
||||
while ((x = bms_first_member(tmpset)) >= 0)
|
||||
x = -1;
|
||||
while ((x = bms_next_member(bms, x)) >= 0)
|
||||
appendStringInfo(str, " %d", x);
|
||||
bms_free(tmpset);
|
||||
appendStringInfoChar(str, ')');
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user