Skip to content

Commit 5179f95

Browse files
JoePerchesakpm00
authored andcommitted
checkpatch: simplify creating search strings
Patch series "checkpatch: refactor and add new alloc w/ multiply tests". Original alloc function patch by Gustavo Silva. This patch (of 2): Use join and map instead of loops. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/ef2ab1a00367e201879d9bff44a2e7e936b87a7e.1694636817.git.joe@perches.com Signed-off-by: Joe Perches <[email protected]> Cc: Andy Whitcroft <[email protected]> (maintainer:CHECKPATCH) Cc: Dwaipayan Ray <[email protected]> (reviewer:CHECKPATCH) Cc: Gustavo A. R. Silva <[email protected]> Cc: Lukas Bulwahn <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 9ea20da commit 5179f95

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

scripts/checkpatch.pl

+7-27
Original file line numberDiff line numberDiff line change
@@ -625,18 +625,8 @@ sub hash_show_words {
625625
our @link_tags = qw(Link Closes);
626626

627627
#Create a search and print patterns for all these strings to be used directly below
628-
our $link_tags_search = "";
629-
our $link_tags_print = "";
630-
foreach my $entry (@link_tags) {
631-
if ($link_tags_search ne "") {
632-
$link_tags_search .= '|';
633-
$link_tags_print .= ' or ';
634-
}
635-
$entry .= ':';
636-
$link_tags_search .= $entry;
637-
$link_tags_print .= "'$entry'";
638-
}
639-
$link_tags_search = "(?:${link_tags_search})";
628+
our $link_tags_search = '(?:' . join('|', @link_tags) . ')';
629+
our $link_tags_print = "'" . join("' or '", @link_tags) . "'";
640630

641631
our $tracing_logging_tags = qr{(?xi:
642632
[=-]*> |
@@ -819,15 +809,10 @@ sub find_standard_signature {
819809
["__ATTR", 2],
820810
);
821811

822-
my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
823-
824812
#Create a search pattern for all these functions to speed up a loop below
825-
our $mode_perms_search = "";
826-
foreach my $entry (@mode_permission_funcs) {
827-
$mode_perms_search .= '|' if ($mode_perms_search ne "");
828-
$mode_perms_search .= $entry->[0];
829-
}
830-
$mode_perms_search = "(?:${mode_perms_search})";
813+
our $mode_perms_search = '(?:' . join('|', map{$_->[0]} @mode_permission_funcs) . ')';
814+
815+
my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
831816

832817
our %deprecated_apis = (
833818
"synchronize_rcu_bh" => "synchronize_rcu",
@@ -847,12 +832,7 @@ sub find_standard_signature {
847832
);
848833

849834
#Create a search pattern for all these strings to speed up a loop below
850-
our $deprecated_apis_search = "";
851-
foreach my $entry (keys %deprecated_apis) {
852-
$deprecated_apis_search .= '|' if ($deprecated_apis_search ne "");
853-
$deprecated_apis_search .= $entry;
854-
}
855-
$deprecated_apis_search = "(?:${deprecated_apis_search})";
835+
our $deprecated_apis_search = '(?:' . join('|', keys %deprecated_apis) . ')';
856836

857837
our $mode_perms_world_writable = qr{
858838
S_IWUGO |
@@ -887,7 +867,7 @@ sub find_standard_signature {
887867
$mode_perms_string_search .= '|' if ($mode_perms_string_search ne "");
888868
$mode_perms_string_search .= $entry;
889869
}
890-
our $single_mode_perms_string_search = "(?:${mode_perms_string_search})";
870+
our $single_mode_perms_string_search = '(?:' . join('|', keys %mode_permission_string_types) . ')';
891871
our $multi_mode_perms_string_search = qr{
892872
${single_mode_perms_string_search}
893873
(?:\s*\|\s*${single_mode_perms_string_search})*

0 commit comments

Comments
 (0)