diff options
| author | bors <bors@rust-lang.org> | 2023-04-20 18:34:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-04-20 18:34:16 +0000 |
| commit | c976ad07ee5ce330b612caff8d49397e8ddcdc28 (patch) | |
| tree | 70c0c3004fe6ca7a4f566c8d20b75c9b6ef180be | |
| parent | 06dace2920edb99eab8b2e714d4e2ea7d5684005 (diff) | |
| parent | 0b16f80c40f650cb5929b2405fd269c62752a8fa (diff) | |
| download | rust-c976ad07ee5ce330b612caff8d49397e8ddcdc28.tar.gz rust-c976ad07ee5ce330b612caff8d49397e8ddcdc28.zip | |
Auto merge of #10675 - c410-f3r:bbbbbbbbbbb, r=llogiq
[arithmetic_side_effects] Cache symbols An internal-only modification to speed up the processing of symbols because "intern" isn't very cheap, even more when you are doing the same thing for every method expression. changelog: none
| -rw-r--r-- | clippy_lints/src/operators/arithmetic_side_effects.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index 2e3925f53dd..fafcf257094 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -11,7 +11,10 @@ use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; use rustc_session::impl_lint_pass; -use rustc_span::source_map::{Span, Spanned}; +use rustc_span::{ + source_map::{Span, Spanned}, + Symbol, +}; const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[ ["f32", "f32"], @@ -21,6 +24,7 @@ const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[ ["std::string::String", "&str"], ]; const HARD_CODED_ALLOWED_UNARY: &[&str] = &["f32", "f64", "std::num::Saturating", "std::num::Wrapping"]; +const INTEGER_METHODS: &[&str] = &["saturating_div", "wrapping_div", "wrapping_rem", "wrapping_rem_euclid"]; #[derive(Debug)] pub struct ArithmeticSideEffects { @@ -29,6 +33,7 @@ pub struct ArithmeticSideEffects { // Used to check whether expressions are constants, such as in enum discriminants and consts const_span: Option<Span>, expr_span: Option<Span>, + integer_methods: FxHashSet<Symbol>, } impl_lint_pass!(ArithmeticSideEffects => [ARITHMETIC_SIDE_EFFECTS]); @@ -54,6 +59,7 @@ impl ArithmeticSideEffects { allowed_unary, const_span: None, expr_span: None, + integer_methods: INTEGER_METHODS.iter().map(|el| Symbol::intern(el)).collect(), } } @@ -194,7 +200,6 @@ impl ArithmeticSideEffects { ps: &hir::PathSegment<'tcx>, receiver: &hir::Expr<'tcx>, ) { - const METHODS: &[&str] = &["saturating_div", "wrapping_div", "wrapping_rem", "wrapping_rem_euclid"]; let Some(arg) = args.first() else { return; }; if constant_simple(cx, cx.typeck_results(), receiver).is_some() { return; @@ -203,7 +208,7 @@ impl ArithmeticSideEffects { if !Self::is_integral(instance_ty) { return; } - if METHODS.iter().copied().all(|method| method != ps.ident.as_str()) { + if !self.integer_methods.contains(&ps.ident.name) { return; } let (actual_arg, _) = peel_hir_expr_refs(arg); |
