mirror of
https://github.com/postgres/postgres.git
synced 2025-10-29 22:49:41 +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:
@@ -2456,11 +2456,10 @@ static Bitmapset *
|
||||
adjust_view_column_set(Bitmapset *cols, List *targetlist)
|
||||
{
|
||||
Bitmapset *result = NULL;
|
||||
Bitmapset *tmpcols;
|
||||
AttrNumber col;
|
||||
int col;
|
||||
|
||||
tmpcols = bms_copy(cols);
|
||||
while ((col = bms_first_member(tmpcols)) >= 0)
|
||||
col = -1;
|
||||
while ((col = bms_next_member(cols, col)) >= 0)
|
||||
{
|
||||
/* bit numbers are offset by FirstLowInvalidHeapAttributeNumber */
|
||||
AttrNumber attno = col + FirstLowInvalidHeapAttributeNumber;
|
||||
@@ -2510,7 +2509,6 @@ adjust_view_column_set(Bitmapset *cols, List *targetlist)
|
||||
attno);
|
||||
}
|
||||
}
|
||||
bms_free(tmpcols);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -454,13 +454,11 @@ static Relids
|
||||
offset_relid_set(Relids relids, int offset)
|
||||
{
|
||||
Relids result = NULL;
|
||||
Relids tmprelids;
|
||||
int rtindex;
|
||||
|
||||
tmprelids = bms_copy(relids);
|
||||
while ((rtindex = bms_first_member(tmprelids)) >= 0)
|
||||
rtindex = -1;
|
||||
while ((rtindex = bms_next_member(relids, rtindex)) >= 0)
|
||||
result = bms_add_member(result, rtindex + offset);
|
||||
bms_free(tmprelids);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user