Skip to content

Commit

Permalink
Avoid &String type and un-necessary cloning
Browse files Browse the repository at this point in the history
Summary: As per title. Suggested in D54633456.

Reviewed By: michalmuskala, alanz

Differential Revision: D54635043

fbshipit-source-id: 5b4cc1c1e635ec8c71e78ab32955709c2d3554ae
  • Loading branch information
robertoaloi authored and facebook-github-bot committed Mar 8, 2024
1 parent 44ca9b6 commit 263b584
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/elp/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Config {
.data
.diagnostics_disabled
.iter()
.filter_map(DiagnosticCode::maybe_from_string)
.filter_map(|code| DiagnosticCode::maybe_from_string(&code))
{
config = config.disable(code);
}
Expand Down
10 changes: 5 additions & 5 deletions crates/ide_db/src/diagnostic_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl DiagnosticCode {
format!("{} ({})", self.as_code(), self.as_label())
}

pub fn maybe_from_string(s: &String) -> Option<DiagnosticCode> {
pub fn maybe_from_string(s: &str) -> Option<DiagnosticCode> {
DIAGNOSTIC_CODE_LOOKUPS
.get(s).cloned()
// @fb-only: .or_else(|| MetaOnlyDiagnosticCode::from_str(s).ok().map(DiagnosticCode::MetaOnly))
Expand Down Expand Up @@ -255,7 +255,7 @@ lazy_static! {
impl FromStr for DiagnosticCode {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Some(code) = DiagnosticCode::maybe_from_string(&s.to_string()) {
if let Some(code) = DiagnosticCode::maybe_from_string(s) {
Ok(code)
} else {
Err(format!("Unknown DiagnosticCode: '{s}'"))
Expand Down Expand Up @@ -290,7 +290,7 @@ mod tests {
let strings = vec!["W0008", "unreachable_test"];
let codes = strings
.iter()
.map(|s| DiagnosticCode::maybe_from_string(&s.to_string()))
.map(|s| DiagnosticCode::maybe_from_string(s))
.collect::<Vec<_>>();
expect![[r#"
[
Expand All @@ -313,7 +313,7 @@ mod tests {
];
let codes = strings
.iter()
.map(|s| DiagnosticCode::maybe_from_string(&s.to_string()))
.map(|s| DiagnosticCode::maybe_from_string(s))
.collect::<Vec<_>>();
expect![[r#"
[
Expand All @@ -337,7 +337,7 @@ mod tests {
let strings = vec!["C1000", "L1213"];
let codes = strings
.iter()
.map(|s| DiagnosticCode::maybe_from_string(&s.to_string()))
.map(|s| DiagnosticCode::maybe_from_string(s))
.collect::<Vec<_>>();
expect![[r#"
[
Expand Down
2 changes: 1 addition & 1 deletion crates/ide_db/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn collect_fixmes(
let comment_range = TextRange::new(pattern_start, pattern_end);
let codes = comment
.split_whitespace()
.filter_map(|word| DiagnosticCode::maybe_from_string(&word.to_string()))
.filter_map(|word| DiagnosticCode::maybe_from_string(word))
.collect();

fixmes.push(Fixme {
Expand Down

0 comments on commit 263b584

Please sign in to comment.