Skip to content

Commit 93f2258

Browse files
committed
Use iteration instead of indexing to access ribs.
This gives a small but noticeable performance improvement.
1 parent 99d02fb commit 93f2258

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

compiler/rustc_resolve/src/ident.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
311311

312312
// Walk backwards up the ribs in scope.
313313
let mut module = self.graph_root;
314-
for i in (0..ribs.len()).rev() {
315-
debug!("walk rib\n{:?}", ribs[i].bindings);
314+
for (i, rib) in ribs.iter().enumerate().rev() {
315+
debug!("walk rib\n{:?}", rib.bindings);
316316
// Use the rib kind to determine whether we are resolving parameters
317317
// (macro 2.0 hygiene) or local variables (`macro_rules` hygiene).
318-
let rib_ident = if ribs[i].kind.contains_params() { normalized_ident } else { ident };
319-
if let Some((original_rib_ident_def, res)) = ribs[i].bindings.get_key_value(&rib_ident)
320-
{
318+
let rib_ident = if rib.kind.contains_params() { normalized_ident } else { ident };
319+
if let Some((original_rib_ident_def, res)) = rib.bindings.get_key_value(&rib_ident) {
321320
// The ident resolves to a type parameter or local variable.
322321
return Some(LexicalScopeBinding::Res(self.validate_res_from_ribs(
323322
i,
@@ -329,7 +328,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
329328
)));
330329
}
331330

332-
module = match ribs[i].kind {
331+
module = match rib.kind {
333332
RibKind::Module(module) => module,
334333
RibKind::MacroDefinition(def) if def == self.macro_def(ident.span.ctxt()) => {
335334
// If an invocation of this macro created `ident`, give up on `ident`

0 commit comments

Comments
 (0)