| 225 | type Item = (&'a K, &'a V); |
| 226 | |
| 227 | fn next(&mut self) -> Option<Self::Item> { |
| 228 | // STREAMLINED CONTROL FLOW: Eliminate finished flag, reduce branching |
| 229 | // |
| 230 | // Key optimizations: |
| 231 | // 1. Use current_leaf_ref.is_none() as terminal state (no finished flag) |
| 232 | // 2. Direct flow with fewer nested conditions |
| 233 | // 3. Simplified advance_to_next_leaf_direct() with bool return |
| 234 | // 4. Single exit point pattern |
| 235 | |
| 236 | loop { |
| 237 | // Direct access - if no leaf, we're done (terminal state) |
| 238 | let leaf = self.current_leaf_ref?; |
| 239 | |
| 240 | // Try current leaf first |
| 241 | if let Some(item) = self.try_get_next_item(leaf) { |
| 242 | return Some(item); |
| 243 | } |
| 244 | |
| 245 | // Advance to next leaf - if false, we're done |
| 246 | if !self.advance_to_next_leaf_direct() { |
| 247 | return None; |
| 248 | } |
| 249 | // Continue with next leaf |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | // ============================================================================ |