diff options
author | Kenneth Graunke <[email protected]> | 2014-01-10 16:39:17 -0800 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2014-01-13 11:49:42 -0800 |
commit | 48d0faaa4388f411ea64fef8f4be04c22d02a4cf (patch) | |
tree | 437426abb4ce6ec3e6c67cd0758d8831f1b38dc0 /src/glsl/list.h | |
parent | 02ff2a275892aa180c84fa2fbb5b44409218c0f3 (diff) |
glsl: Use a new foreach_two_lists macro for walking two lists at once.
When handling function calls, we often want to walk through the list of
formal parameters and list of actual parameters at the same time.
(Both are guaranteed to be the same length.)
Previously, we used a pattern of:
exec_list_iterator 1st_iter = <1st list>.iterator();
foreach_iter(exec_list_iterator, 2nd_iter, <2nd list>) {
...
1st_iter.next();
}
This was awkward, since you had to manually iterate through one of
the two lists.
This patch introduces a foreach_two_lists macro which safely walks
through two lists at the same time, so you can simply do:
foreach_two_lists(1st_node, <1st list>, 2nd_node, <2nd list>) {
...
}
v2: Rename macro from foreach_list2 to foreach_two_lists, as suggested
by Ian Romanick.
Signed-off-by: Kenneth Graunke <[email protected]>
Reviewed-by: Matt Turner <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl/list.h')
-rw-r--r-- | src/glsl/list.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/glsl/list.h b/src/glsl/list.h index 5ac17cb37a4..f9eb60ec7c4 100644 --- a/src/glsl/list.h +++ b/src/glsl/list.h @@ -447,6 +447,22 @@ inline void exec_node::insert_before(exec_list *before) ; (__node)->next != NULL \ ; (__node) = (__node)->next) +/** + * Iterate through two lists at once. Stops at the end of the shorter list. + * + * This is safe against either current node being removed or replaced. + */ +#define foreach_two_lists(__node1, __list1, __node2, __list2) \ + for (exec_node * __node1 = (__list1)->head, \ + * __node2 = (__list2)->head, \ + * __next1 = __node1->next, \ + * __next2 = __node2->next \ + ; __next1 != NULL && __next2 != NULL \ + ; __node1 = __next1, \ + __node2 = __next2, \ + __next1 = __next1->next, \ + __next2 = __next2->next) + #define foreach_list_const(__node, __list) \ for (const exec_node * __node = (__list)->head \ ; (__node)->next != NULL \ |