From babe1eb7be3e3ba8e934cbd42d93434fec8e5b4e Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Sat, 21 Jan 2023 02:06:48 +0100 Subject: [PATCH] perf: Reduce allocations (#2045) I found a few places where some allocations could be avoided. --- src/flake8_to_ruff/converter.rs | 6 +++--- src/rules/flake8_annotations/rules.rs | 8 ++++---- src/rules/flake8_pytest_style/rules/fixture.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/flake8_to_ruff/converter.rs b/src/flake8_to_ruff/converter.rs index b7b72bed53..449cb00721 100644 --- a/src/flake8_to_ruff/converter.rs +++ b/src/flake8_to_ruff/converter.rs @@ -104,7 +104,7 @@ pub fn convert( "builtins" => { options.builtins = Some(parser::parse_strings(value.as_ref())); } - "max-line-length" | "max_line_length" => match value.clone().parse::() { + "max-line-length" | "max_line_length" => match value.parse::() { Ok(line_length) => options.line_length = Some(line_length), Err(e) => { warn_user!("Unable to parse '{key}' property: {e}"); @@ -241,7 +241,7 @@ pub fn convert( } }, // mccabe - "max-complexity" | "max_complexity" => match value.clone().parse::() { + "max-complexity" | "max_complexity" => match value.parse::() { Ok(max_complexity) => mccabe.max_complexity = Some(max_complexity), Err(e) => { warn_user!("Unable to parse '{key}' property: {e}"); @@ -249,7 +249,7 @@ pub fn convert( }, // flake8-errmsg "errmsg-max-string-length" | "errmsg_max_string_length" => { - match value.clone().parse::() { + match value.parse::() { Ok(max_string_length) => { flake8_errmsg.max_string_length = Some(max_string_length); } diff --git a/src/rules/flake8_annotations/rules.rs b/src/rules/flake8_annotations/rules.rs index a2b9c86817..c6d456d2c4 100644 --- a/src/rules/flake8_annotations/rules.rs +++ b/src/rules/flake8_annotations/rules.rs @@ -119,7 +119,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V .rules .enabled(&Rule::DynamicallyTypedExpression) { - let name = arg.node.arg.to_string(); + let name = &arg.node.arg; check_dynamically_typed(checker, expr, || format!("*{name}")); } } @@ -146,7 +146,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V .rules .enabled(&Rule::DynamicallyTypedExpression) { - let name = arg.node.arg.to_string(); + let name = &arg.node.arg; check_dynamically_typed(checker, expr, || format!("**{name}")); } } @@ -266,7 +266,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V .rules .enabled(&Rule::DynamicallyTypedExpression) { - let name = arg.node.arg.to_string(); + let name = &arg.node.arg; check_dynamically_typed(checker, expr, || format!("*{name}")); } } @@ -294,7 +294,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V .rules .enabled(&Rule::DynamicallyTypedExpression) { - let name = arg.node.arg.to_string(); + let name = &arg.node.arg; check_dynamically_typed(checker, expr, || format!("**{name}")); } } diff --git a/src/rules/flake8_pytest_style/rules/fixture.rs b/src/rules/flake8_pytest_style/rules/fixture.rs index 9958be38e6..21430a8a20 100644 --- a/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/src/rules/flake8_pytest_style/rules/fixture.rs @@ -217,10 +217,10 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo /// PT019 fn check_test_function_args(checker: &mut Checker, args: &Arguments) { args.args.iter().chain(&args.kwonlyargs).for_each(|arg| { - let name = arg.node.arg.to_string(); + let name = &arg.node.arg; if name.starts_with('_') { checker.diagnostics.push(Diagnostic::new( - violations::FixtureParamWithoutValue(name), + violations::FixtureParamWithoutValue(name.to_string()), Range::from_located(arg), )); }