aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-12-22 18:31:20 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-12-22 18:31:20 +0000
commit59b2d84fe92f4f64a2ddc6050f1aee160c227327 (patch)
tree11d4a81cadab27efa9943341e5cdb89e6b3b1c72
parente45dec291dead56870bf266ff0c280adfaff23f6 (diff)
downloadrpmdrake-59b2d84fe92f4f64a2ddc6050f1aee160c227327.tar
rpmdrake-59b2d84fe92f4f64a2ddc6050f1aee160c227327.tar.gz
rpmdrake-59b2d84fe92f4f64a2ddc6050f1aee160c227327.tar.bz2
rpmdrake-59b2d84fe92f4f64a2ddc6050f1aee160c227327.tar.xz
rpmdrake-59b2d84fe92f4f64a2ddc6050f1aee160c227327.zip
Optimize search by compiling and eval'ing regexps only once
-rwxr-xr-xrpmdrake23
1 files changed, 15 insertions, 8 deletions
diff --git a/rpmdrake b/rpmdrake
index 68ef4817..cc8cf469 100755
--- a/rpmdrake
+++ b/rpmdrake
@@ -392,6 +392,7 @@ sub db {
sub do_search($$$$$$$) {
my ($find_entry, $tree, $tree_model, $options, $current_search_type, $urpm, $pkgs) = @_;
my $entry = quotemeta $find_entry->get_text or return;
+ my $entry_rx = eval { qr/$entry/i } or return;
my ($results_ok, $results_none) = (N("Search results"), N("Search results (none)"));
$options->{delete_category}->($_) foreach $results_ok, $results_none;
$options->{state}{flat} and $options->{delete_all}->();
@@ -400,11 +401,17 @@ sub do_search($$$$$$$) {
if ($current_search_type ne 'normal') {
if ($MODE eq 'remove') {
if ($current_search_type eq 'descriptions') {
- @search_results = grep { eval { ($pkgs->{$_}{summary} . $pkgs->{$_}{description}) =~ /$entry/i } } keys %$pkgs;
+ @search_results = grep { ($pkgs->{$_}{summary} . $pkgs->{$_}{description}) =~ $entry_rx } keys %$pkgs;
} else {
- slow_func(N("Please wait, searching..."),
- sub { db->traverse(sub { push @search_results, map { if_(eval { /$entry/i }, my_fullname($_[0])) } $_[0]->files });
- @search_results = grep { exists $pkgs->{$_} } uniq(@search_results) });
+ slow_func(
+ N("Please wait, searching..."),
+ sub {
+ db->traverse(sub {
+ push @search_results, map { if_(($_ =~ $entry_rx), my_fullname($_[0])) } $_[0]->files;
+ });
+ @search_results = grep { exists $pkgs->{$_} } uniq(@search_results);
+ },
+ );
}
} else {
my @hdlists = map { my $h = "$urpm->{statedir}/$_->{hdlist}";
@@ -441,7 +448,7 @@ sub do_search($$$$$$$) {
} else {
$key eq 'files' or next;
}
- if (eval { $value =~ /$entry/i }) {
+ if ($value =~ $entry_rx) {
exists $pkgs->{$pkg} and push @search_results, $pkg;
$pkg = '';
}
@@ -451,7 +458,7 @@ sub do_search($$$$$$$) {
$searchw->destroy;
}
} else {
- @search_results = grep { eval { /$entry/i } } keys %$pkgs;
+ @search_results = grep { $_ =~ $entry_rx } keys %$pkgs;
}
if (@search_results) {
$options->{add_nodes}->(map { [ $_, N("Search results") . ($options->{tree_mode} eq 'by_presence'
@@ -867,9 +874,9 @@ or you already installed all of them."));
flat => { name => N("All packages, alphabetical"), flat => 1 },
by => { name => '', flat => 0 },
);
- $compssUsers = parse_compssUsers_flat();
my @radios_names_ordered = qw(mandrake_choices flat by);
- $compssUsers or shift @radios_names_ordered;
+ $compssUsers = parse_compssUsers_flat()
+ or shift @radios_names_ordered;
my @advanced_modes = (
[ 'by_group', N("All packages, by group"), 0 ],