mirror of
https://github.com/postgres/postgres.git
synced 2025-11-21 00:42:43 +03:00
Add macros for looping through a List without a ListCell.
Many foreach loops only use the ListCell pointer to retrieve the
content of the cell, like so:
ListCell *lc;
foreach(lc, mylist)
{
int myint = lfirst_int(lc);
...
}
This commit adds a few convenience macros that automatically
declare the loop variable and retrieve the current cell's contents.
This allows us to rewrite the previous loop like this:
foreach_int(myint, mylist)
{
...
}
This commit also adjusts a few existing loops in order to add
coverage for the new/adjusted macros. There is presently no plan
to bulk update all foreach loops, as that could introduce a
significant amount of back-patching pain. Instead, these macros
are primarily intended for use in new code.
Author: Jelte Fennema-Nio
Reviewed-by: David Rowley, Alvaro Herrera, Vignesh C, Tom Lane
Discussion: https://postgr.es/m/CAGECzQSwXKnxGwW1_Q5JE%2B8Ja20kyAbhBHO04vVrQsLcDciwXA%40mail.gmail.com
This commit is contained in:
@@ -2234,7 +2234,6 @@ cleanup_rel_sync_cache(TransactionId xid, bool is_commit)
|
||||
{
|
||||
HASH_SEQ_STATUS hash_seq;
|
||||
RelationSyncEntry *entry;
|
||||
ListCell *lc;
|
||||
|
||||
Assert(RelationSyncCache != NULL);
|
||||
|
||||
@@ -2247,15 +2246,15 @@ cleanup_rel_sync_cache(TransactionId xid, bool is_commit)
|
||||
* corresponding schema and we don't need to send it unless there is
|
||||
* any invalidation for that relation.
|
||||
*/
|
||||
foreach(lc, entry->streamed_txns)
|
||||
foreach_xid(streamed_txn, entry->streamed_txns)
|
||||
{
|
||||
if (xid == lfirst_xid(lc))
|
||||
if (xid == streamed_txn)
|
||||
{
|
||||
if (is_commit)
|
||||
entry->schema_sent = true;
|
||||
|
||||
entry->streamed_txns =
|
||||
foreach_delete_current(entry->streamed_txns, lc);
|
||||
foreach_delete_current(entry->streamed_txns, streamed_txn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user