diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-11-07 16:08:26 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-11-13 08:44:00 +1100 |
| commit | 93f225856557d5930b64b329237a9a43e09637bc (patch) | |
| tree | 89e393c4171ded3b35dd696c0b9a79513ba0e060 | |
| parent | 99d02fb40fd339255ed08596ebeb41e9b8a09d45 (diff) | |
| download | rust-93f225856557d5930b64b329237a9a43e09637bc.tar.gz rust-93f225856557d5930b64b329237a9a43e09637bc.zip | |
Use iteration instead of indexing to access ribs.
This gives a small but noticeable performance improvement.
| -rw-r--r-- | compiler/rustc_resolve/src/ident.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index b80e0e196ca..c8f7a12132c 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -311,13 +311,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // Walk backwards up the ribs in scope. let mut module = self.graph_root; - for i in (0..ribs.len()).rev() { - debug!("walk rib\n{:?}", ribs[i].bindings); + for (i, rib) in ribs.iter().enumerate().rev() { + debug!("walk rib\n{:?}", rib.bindings); // Use the rib kind to determine whether we are resolving parameters // (macro 2.0 hygiene) or local variables (`macro_rules` hygiene). - let rib_ident = if ribs[i].kind.contains_params() { normalized_ident } else { ident }; - if let Some((original_rib_ident_def, res)) = ribs[i].bindings.get_key_value(&rib_ident) - { + let rib_ident = if rib.kind.contains_params() { normalized_ident } else { ident }; + if let Some((original_rib_ident_def, res)) = rib.bindings.get_key_value(&rib_ident) { // The ident resolves to a type parameter or local variable. return Some(LexicalScopeBinding::Res(self.validate_res_from_ribs( i, @@ -329,7 +328,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ))); } - module = match ribs[i].kind { + module = match rib.kind { RibKind::Module(module) => module, RibKind::MacroDefinition(def) if def == self.macro_def(ident.span.ctxt()) => { // If an invocation of this macro created `ident`, give up on `ident` |
