Skip to content

Commit ac5d704

Browse files
authored
[perf] Use slices instead of HashSet for reserved method name checks (#823)
* [perf] Use slices instead of HashSet for reserved method name checks * Clippy
1 parent 0267003 commit ac5d704

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

librubyfmt/src/format_prism.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, collections::HashSet, sync::LazyLock};
1+
use std::borrow::Cow;
22

33
use ruby_prism as prism;
44

@@ -1632,18 +1632,11 @@ fn format_block_argument_node<'src>(
16321632
}
16331633
}
16341634

1635-
pub static RSPEC_METHODS: LazyLock<HashSet<&'static str>> =
1636-
LazyLock::new(|| vec!["it", "describe"].into_iter().collect());
1635+
pub static RSPEC_METHODS: [&str; 2] = ["it", "describe"];
16371636

1638-
pub static GEMFILE_METHODS: LazyLock<HashSet<&'static str>> =
1639-
LazyLock::new(|| vec!["gem", "source", "ruby", "group"].into_iter().collect());
1637+
pub static GEMFILE_METHODS: [&str; 4] = ["gem", "source", "ruby", "group"];
16401638

1641-
pub static OPTIONALLY_PARENTHESIZED_METHODS: LazyLock<HashSet<&'static str>> =
1642-
LazyLock::new(|| {
1643-
vec!["super", "require", "require_relative"]
1644-
.into_iter()
1645-
.collect::<HashSet<_>>()
1646-
});
1639+
pub static OPTIONALLY_PARENTHESIZED_METHODS: [&str; 3] = ["super", "require", "require_relative"];
16471640

16481641
fn use_parens_for_call_node<'src>(
16491642
ps: &ParserState<'src>,
@@ -1712,8 +1705,8 @@ fn use_parens_for_call_node<'src>(
17121705
return false;
17131706
}
17141707

1715-
if OPTIONALLY_PARENTHESIZED_METHODS.contains(method_name)
1716-
|| GEMFILE_METHODS.contains(method_name)
1708+
if OPTIONALLY_PARENTHESIZED_METHODS.contains(&method_name)
1709+
|| GEMFILE_METHODS.contains(&method_name)
17171710
{
17181711
return original_used_parens;
17191712
}
@@ -1733,7 +1726,7 @@ fn use_parens_for_call_node<'src>(
17331726
return true;
17341727
}
17351728

1736-
if RSPEC_METHODS.contains(method_name)
1729+
if RSPEC_METHODS.contains(&method_name)
17371730
&& call_node.receiver().is_none()
17381731
// Only elide parens for blocks, not block params (`&blk`)
17391732
&& call_node

0 commit comments

Comments
 (0)