ITADN

perf: optimize transitions and path handling using sets

#2051Pull Requestallrob23 创建于 2025-03-04已合并
A
allrob23commented
## Description This PR improves performance by replacing list-based operations with sets in `allowed_transitions` and `safe_paths`. Using sets instead of lists reduces lookup time from **O(n) to O(1)** in most cases, leading to better efficiency. ### Changes: - Replaced `+=` with `.update()` in `allowed_transitions` to leverage set operations. - Used `set()` for `safe_paths` instead of a list to optimize lookups. ### Why is this needed? - **Faster lookups**: Checking membership in a set is **O(1)** on average, whereas lists are **O(n)**. - **Cleaner and more idiomatic Python**: Sets are the right data structure for unique unordered elements. - **Improved maintainability**: Ensures consistent use of efficient data structures. ### Impact These changes should have **no functional impact** but will improve performance in cases where transitions or paths are frequently checked.
合并状态:已合并 合并于 2025-03-06 关闭于 2025-03-06 6 条评论