mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 14:40:19 +00:00
47fa620034
# Objective `update_accessibility_nodes` is one of the most nested functions in the entire Bevy repository, with a maximum of 9 levels of indentations. This PR refactors it down to 3 levels of indentations, while improving readability on other fronts. The result is a function that is actually understandable at a first glance. - This is a proof of concept to demonstrate that it is possible to gradually lower the nesting limit proposed by #10896. PS: I read AccessKit's documentation, but I don't have experience with it. Therefore, naming of variables and subroutines may be a bit off. PS2: I don't know if the test suite covers the functionality of this system, but since I've spent quite some time on it and the changes were simple, I'm pretty confident the refactor is functionally equivalent to the original. ## Solution I documented each change with a commit, but as a summary I did the following to reduce nesting: - I moved from `if-let` blocks to `let-else` statements where appropriate to reduce rightward shift - I extracted the closure body to a new function `update_adapter` - I factored out parts of `update_adapter` into new functions `queue_node_for_update` and `add_children_nodes` **Note for reviewers:** GitHub's diff viewer is not the greatest in showing horizontal code shifts, therefore you may want to use a different tool like VSCode to review some commits, especially the second one (anyway, that commit is very straightforward, despite changing many lines). |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |