aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Guldstrand <andreas.guldstrand@gmail.com>2017-05-30 02:11:45 +0200
committerAndreas Guldstrand <andreas.guldstrand@gmail.com>2017-05-30 02:16:20 +0200
commit00047a7a8c312f3bba73f7a8f09dd751f96fdb31 (patch)
treee21eaa552f88a037a5521404628baa385aac0f6b
parente6f5094d9eaf2df9c48c2d6ae9e0ecd2f71263ec (diff)
downloadsbotools-00047a7a8c312f3bba73f7a8f09dd751f96fdb31.tar.xz
sbofind: optimise searching
On my machine, before this commit, 'sbofind R' would spend 2.5 minutes searching, 6.5 minutes outputting results After this commit, 'sbofind R' would spend 4 seconds searching, 6.5 minutes outputting results See #48.
-rwxr-xr-xsbofind47
1 files changed, 28 insertions, 19 deletions
diff --git a/sbofind b/sbofind
index 9869ee9..14e018f 100755
--- a/sbofind
+++ b/sbofind
@@ -97,28 +97,37 @@ sub perform_search {
}
my (%local, @findings);
FIRST: while (my $line = <$fh>) {
- next FIRST unless $line =~ /NAME:/;
+ if ($line =~ /NAME:\s+(.*)$/) {
+ my $name = $1;
- # Try to match either the search string or any of the names from the TAGS.txt
- foreach my $search ($search_name_re, map { quotemeta } @names) {
- if (my ($name) = $line =~ /NAME:\s+($search)$/i) {
+ # Try to match either one of the names from TAGS.txt or the search string
- # If the name matches a local override, use its location
- if ($config{LOCAL_OVERRIDES} ne 'FALSE' and -d "$config{LOCAL_OVERRIDES}/$name") {
- push @findings, {name => $name, location => "$config{LOCAL_OVERRIDES}/$name", local => 1 };
- $local{$name} = 1;
- next FIRST;
- }
+ my $names = @names;
+ # Whenever we find an element equal to $name, throw it away (and
+ # replace with last element rather than shifting stuff around)
+ for (reverse @names) { $_ = pop @names if $_ eq $name; }
+
+ # next if $name didn't match either one of @names or $search_name_re
+ if ($names == @names and $name !~ /$search_name_re/i) { next FIRST; }
+
+ # We only reach this point if $name matched one of @names, or if
+ # $search_name_re matched
- # Otherwise the location should be in the next line
- LOCATION: {
- my $loc_line = <$fh>;
- if (my ($location) = $loc_line =~ $loc_regex) {
- push @findings, {name => $name, location => $repo_path . $location};
- next FIRST;
- } else {
- redo LOCATION; # But if it isn't, we try again...
- }
+ # If the name matches a local override, use its location
+ if ($config{LOCAL_OVERRIDES} ne 'FALSE' and -d "$config{LOCAL_OVERRIDES}/$name") {
+ push @findings, {name => $name, location => "$config{LOCAL_OVERRIDES}/$name", local => 1 };
+ $local{$name} = 1;
+ next FIRST;
+ }
+
+ # Otherwise the location should be in the next line
+ LOCATION: {
+ my $loc_line = <$fh>;
+ if (my ($location) = $loc_line =~ $loc_regex) {
+ push @findings, {name => $name, location => $repo_path . $location};
+ next FIRST;
+ } else {
+ redo LOCATION; # But if it isn't, we try again...
}
}
}