Esme Povirk (@madewokherd) commented about dlls/uiautomationcore/uia_client.c:
+ * huianode doesn't match our stop condition. + */ + hr = uia_condition_check(huianode, pre_sibling_nav_stop_cond); + if (FAILED(hr) || uia_condition_matched(hr)) + goto exit; + + /* Now, check for any siblings to visit. */ + if (traversal_opts & TreeTraversalOptions_LastToFirstOrder) + hr = traverse_uia_node_tree_siblings(huianode, ascending_stop_cond, NavigateDirection_PreviousSibling, + at_root_level, &node2); + else + hr = traverse_uia_node_tree_siblings(huianode, ascending_stop_cond, NavigateDirection_NextSibling, + at_root_level, &node2); + + if (SUCCEEDED(hr) && node2) + hr = traverse_uia_node_tree(node2, view_cond, search_cond, pre_sibling_nav_stop_cond, ascending_stop_cond, I think it would be worth manually tail-call-optimizing this so we don't need a stack frame for every sibling we traverse (basically reassign node and go back to start). Maybe convert the whole thing to a loop of some sort?
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/1249#note_14104