From 14dd0f27d7cd56ffae9ecdbe324965073d01a9ff Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Thu, 4 Jan 2024 16:09:34 -0600 Subject: 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 --- src/backend/replication/logical/tablesync.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/backend/replication/logical/tablesync.c') diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index e8cc9ac5522..06d5b3df33a 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -1036,11 +1036,11 @@ fetch_remote_table_info(char *nspname, char *relname, /* Build the pubname list. */ initStringInfo(&pub_names); - foreach(lc, MySubscription->publications) + foreach_node(String, pubstr, MySubscription->publications) { - char *pubname = strVal(lfirst(lc)); + char *pubname = strVal(pubstr); - if (foreach_current_index(lc) > 0) + if (foreach_current_index(pubstr) > 0) appendStringInfoString(&pub_names, ", "); appendStringInfoString(&pub_names, quote_literal_cstr(pubname)); -- cgit v1.2.3