|
1 | | -use core::ops::ControlFlow; |
2 | 1 | use std::borrow::Cow; |
3 | 2 |
|
4 | | -use rustc_ast::visit::Visitor; |
5 | 3 | use rustc_ast::*; |
6 | 4 | use rustc_data_structures::fx::FxIndexMap; |
7 | 5 | use rustc_hir as hir; |
@@ -476,16 +474,10 @@ fn expand_format_args<'hir>( |
476 | 474 | return hir::ExprKind::Call(new, new_args); |
477 | 475 | } |
478 | 476 |
|
479 | | - // If the args array contains exactly all the original arguments once, |
480 | | - // in order, we can use a simple array instead of a `match` construction. |
481 | | - // However, if there's a yield point in any argument except the first one, |
482 | | - // we don't do this, because an Argument cannot be kept across yield points. |
483 | | - // |
484 | | - // This is an optimization, speeding up compilation about 1-2% in some cases. |
485 | | - // See https://github.com/rust-lang/rust/pull/106770#issuecomment-1380790609 |
486 | | - let use_simple_array = argmap.len() == arguments.len() |
487 | | - && argmap.iter().enumerate().all(|(i, (&(j, _), _))| i == j) |
488 | | - && arguments.iter().skip(1).all(|arg| !may_contain_yield_point(&arg.expr)); |
| 477 | + // If the args array contains just one argument, |
| 478 | + // we can use a simple array instead of a `match` construction. |
| 479 | + let use_simple_array = |
| 480 | + argmap.len() == 1 && arguments.len() == 1 && argmap.first().unwrap().0.0 == 0; |
489 | 481 |
|
490 | 482 | let args = if arguments.is_empty() { |
491 | 483 | // Generate: |
@@ -514,9 +506,6 @@ fn expand_format_args<'hir>( |
514 | 506 | // Generate: |
515 | 507 | // &[ |
516 | 508 | // <core::fmt::Argument>::new_display(&arg0), |
517 | | - // <core::fmt::Argument>::new_lower_hex(&arg1), |
518 | | - // <core::fmt::Argument>::new_debug(&arg2), |
519 | | - // … |
520 | 509 | // ] |
521 | 510 | let elements = ctx.arena.alloc_from_iter(arguments.iter().zip(argmap).map( |
522 | 511 | |(arg, ((_, ty), placeholder_span))| { |
@@ -635,34 +624,6 @@ fn expand_format_args<'hir>( |
635 | 624 | } |
636 | 625 | } |
637 | 626 |
|
638 | | -fn may_contain_yield_point(e: &ast::Expr) -> bool { |
639 | | - struct MayContainYieldPoint; |
640 | | - |
641 | | - impl Visitor<'_> for MayContainYieldPoint { |
642 | | - type Result = ControlFlow<()>; |
643 | | - |
644 | | - fn visit_expr(&mut self, e: &ast::Expr) -> ControlFlow<()> { |
645 | | - if let ast::ExprKind::Await(_, _) | ast::ExprKind::Yield(_) = e.kind { |
646 | | - ControlFlow::Break(()) |
647 | | - } else { |
648 | | - visit::walk_expr(self, e) |
649 | | - } |
650 | | - } |
651 | | - |
652 | | - fn visit_mac_call(&mut self, _: &ast::MacCall) -> ControlFlow<()> { |
653 | | - // Macros should be expanded at this point. |
654 | | - unreachable!("unexpanded macro in ast lowering"); |
655 | | - } |
656 | | - |
657 | | - fn visit_item(&mut self, _: &ast::Item) -> ControlFlow<()> { |
658 | | - // Do not recurse into nested items. |
659 | | - ControlFlow::Continue(()) |
660 | | - } |
661 | | - } |
662 | | - |
663 | | - MayContainYieldPoint.visit_expr(e).is_break() |
664 | | -} |
665 | | - |
666 | 627 | fn for_all_argument_indexes(template: &mut [FormatArgsPiece], mut f: impl FnMut(&mut usize)) { |
667 | 628 | for piece in template { |
668 | 629 | let FormatArgsPiece::Placeholder(placeholder) = piece else { continue }; |
|
0 commit comments