Commit 14dd0f2
committed
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.com1 parent 5e8674d commit 14dd0f2
File tree
5 files changed
+71
-26
lines changed- src
- backend
- executor
- replication
- logical
- pgoutput
- include/nodes
5 files changed
+71
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
220 | 219 | | |
221 | 220 | | |
222 | 221 | | |
| |||
250 | 249 | | |
251 | 250 | | |
252 | 251 | | |
253 | | - | |
| 252 | + | |
254 | 253 | | |
255 | | - | |
256 | | - | |
257 | 254 | | |
258 | 255 | | |
259 | 256 | | |
| |||
265 | 262 | | |
266 | 263 | | |
267 | 264 | | |
268 | | - | |
| 265 | + | |
269 | 266 | | |
270 | | - | |
| 267 | + | |
271 | 268 | | |
272 | 269 | | |
273 | 270 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
746 | 746 | | |
747 | 747 | | |
748 | 748 | | |
749 | | - | |
750 | 749 | | |
751 | | - | |
| 750 | + | |
752 | 751 | | |
753 | | - | |
754 | 752 | | |
755 | 753 | | |
756 | 754 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1036 | 1036 | | |
1037 | 1037 | | |
1038 | 1038 | | |
1039 | | - | |
| 1039 | + | |
1040 | 1040 | | |
1041 | | - | |
| 1041 | + | |
1042 | 1042 | | |
1043 | | - | |
| 1043 | + | |
1044 | 1044 | | |
1045 | 1045 | | |
1046 | 1046 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2234 | 2234 | | |
2235 | 2235 | | |
2236 | 2236 | | |
2237 | | - | |
2238 | 2237 | | |
2239 | 2238 | | |
2240 | 2239 | | |
| |||
2247 | 2246 | | |
2248 | 2247 | | |
2249 | 2248 | | |
2250 | | - | |
| 2249 | + | |
2251 | 2250 | | |
2252 | | - | |
| 2251 | + | |
2253 | 2252 | | |
2254 | 2253 | | |
2255 | 2254 | | |
2256 | 2255 | | |
2257 | 2256 | | |
2258 | | - | |
| 2257 | + | |
2259 | 2258 | | |
2260 | 2259 | | |
2261 | 2260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
384 | | - | |
| 384 | + | |
| 385 | + | |
385 | 386 | | |
386 | | - | |
387 | | - | |
388 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
389 | 390 | | |
390 | | - | |
391 | | - | |
392 | | - | |
| 391 | + | |
| 392 | + | |
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | | - | |
397 | | - | |
| 396 | + | |
| 397 | + | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
403 | | - | |
| 403 | + | |
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
| |||
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
455 | 506 | | |
456 | 507 | | |
457 | 508 | | |
| |||
0 commit comments