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 /contrib/sepgsql/dml.c | |
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 'contrib/sepgsql/dml.c')
-rw-r--r-- | contrib/sepgsql/dml.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/contrib/sepgsql/dml.c b/contrib/sepgsql/dml.c index bb82c0d6d2..9e9fa04746 100644 --- a/contrib/sepgsql/dml.c +++ b/contrib/sepgsql/dml.c @@ -93,10 +93,7 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns) static Bitmapset * fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns) { - AttrNumber attno; - Bitmapset *tmpset; Bitmapset *result = NULL; - char *attname; int index; /* @@ -105,10 +102,12 @@ fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns) if (parentId == childId) return columns; - tmpset = bms_copy(columns); - while ((index = bms_first_member(tmpset)) > 0) + index = -1; + while ((index = bms_next_member(columns, index)) >= 0) { - attno = index + FirstLowInvalidHeapAttributeNumber; + /* bit numbers are offset by FirstLowInvalidHeapAttributeNumber */ + AttrNumber attno = index + FirstLowInvalidHeapAttributeNumber; + char *attname; /* * whole-row-reference shall be fixed-up later @@ -128,12 +127,11 @@ fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns) elog(ERROR, "cache lookup failed for attribute %s of relation %u", attname, childId); - index = attno - FirstLowInvalidHeapAttributeNumber; - result = bms_add_member(result, index); + result = bms_add_member(result, + attno - FirstLowInvalidHeapAttributeNumber); pfree(attname); } - bms_free(tmpset); return result; } |