diff options
author | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-04-22 11:02:17 -0700 |
---|---|---|
committer | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-04-22 11:02:17 -0700 |
commit | 271477d8c26794abd8310e2abb89b746204660af (patch) | |
tree | a4701a52f9ff1918e25a75e09267bfba0b063296 /Bugzilla | |
parent | 3417cb73db6d2306a012d3c624e9bec92fa1a161 (diff) | |
download | bugs-271477d8c26794abd8310e2abb89b746204660af.tar bugs-271477d8c26794abd8310e2abb89b746204660af.tar.gz bugs-271477d8c26794abd8310e2abb89b746204660af.tar.bz2 bugs-271477d8c26794abd8310e2abb89b746204660af.tar.xz bugs-271477d8c26794abd8310e2abb89b746204660af.zip |
Bug 560009: Use firstidx from List::MoreUtils instead of lsearch
r=timello, a=mkanat
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/Bug.pm | 7 | ||||
-rw-r--r-- | Bugzilla/CGI.pm | 2 | ||||
-rw-r--r-- | Bugzilla/Config/Common.pm | 10 | ||||
-rw-r--r-- | Bugzilla/DB/Schema.pm | 7 | ||||
-rw-r--r-- | Bugzilla/Field.pm | 4 | ||||
-rw-r--r-- | Bugzilla/Migrate/Gnats.pm | 15 | ||||
-rw-r--r-- | Bugzilla/Template.pm | 6 | ||||
-rw-r--r-- | Bugzilla/User.pm | 5 | ||||
-rw-r--r-- | Bugzilla/Util.pm | 32 |
9 files changed, 35 insertions, 53 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 3edab563a..def8ad360 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -49,6 +49,7 @@ use Bugzilla::Group; use Bugzilla::Status; use Bugzilla::Comment; +use List::MoreUtils qw(firstidx); use List::Util qw(min first); use Storable qw(dclone); use URI; @@ -3057,8 +3058,10 @@ sub editable_bug_fields { # Obsolete custom fields are not editable. my @obsolete_fields = Bugzilla->get_fields({obsolete => 1, custom => 1}); @obsolete_fields = map { $_->name } @obsolete_fields; - foreach my $remove ("bug_id", "reporter", "creation_ts", "delta_ts", "lastdiffed", @obsolete_fields) { - my $location = lsearch(\@fields, $remove); + foreach my $remove ("bug_id", "reporter", "creation_ts", "delta_ts", + "lastdiffed", @obsolete_fields) + { + my $location = firstidx { $_ eq $remove } @fields; # Custom multi-select fields are not stored in the bugs table. splice(@fields, $location, 1) if ($location > -1); } diff --git a/Bugzilla/CGI.pm b/Bugzilla/CGI.pm index 6e9dfd0ce..75b7f18d7 100644 --- a/Bugzilla/CGI.pm +++ b/Bugzilla/CGI.pm @@ -115,7 +115,7 @@ sub canonicalise_query { my @parameters; foreach my $key (sort($self->param())) { # Leave this key out if it's in the exclude list - next if lsearch(\@exclude, $key) != -1; + next if grep { $_ eq $key } @exclude; # Remove the Boolean Charts for standard query.cgi fields # They are listed in the query URL already diff --git a/Bugzilla/Config/Common.pm b/Bugzilla/Config/Common.pm index 7416b1794..8fc1b6037 100644 --- a/Bugzilla/Config/Common.pm +++ b/Bugzilla/Config/Common.pm @@ -144,7 +144,7 @@ sub check_utf8 { sub check_priority { my ($value) = (@_); my $legal_priorities = get_legal_field_values('priority'); - if (lsearch($legal_priorities, $value) < 0) { + if (!grep($_ eq $value, @$legal_priorities)) { return "Must be a legal priority value: one of " . join(", ", @$legal_priorities); } @@ -154,7 +154,7 @@ sub check_priority { sub check_severity { my ($value) = (@_); my $legal_severities = get_legal_field_values('bug_severity'); - if (lsearch($legal_severities, $value) < 0) { + if (!grep($_ eq $value, @$legal_severities)) { return "Must be a legal severity value: one of " . join(", ", @$legal_severities); } @@ -164,7 +164,7 @@ sub check_severity { sub check_platform { my ($value) = (@_); my $legal_platforms = get_legal_field_values('rep_platform'); - if (lsearch(['', @$legal_platforms], $value) < 0) { + if (!grep($_ eq $value, '', @$legal_platforms)) { return "Must be empty or a legal platform value: one of " . join(", ", @$legal_platforms); } @@ -174,7 +174,7 @@ sub check_platform { sub check_opsys { my ($value) = (@_); my $legal_OS = get_legal_field_values('op_sys'); - if (lsearch(['', @$legal_OS], $value) < 0) { + if (!grep($_ eq $value, '', @$legal_OS)) { return "Must be empty or a legal operating system value: one of " . join(", ", @$legal_OS); } @@ -184,7 +184,7 @@ sub check_opsys { sub check_bug_status { my $bug_status = shift; my @closed_bug_statuses = map {$_->name} closed_bug_statuses(); - if (lsearch(\@closed_bug_statuses, $bug_status) < 0) { + if (!grep($_ eq $bug_status, @closed_bug_statuses)) { return "Must be a valid closed status: one of " . join(', ', @closed_bug_statuses); } return ""; diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 6520766f3..8e0458a51 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -44,6 +44,7 @@ use Bugzilla::Constants; use Carp qw(confess); use Digest::MD5 qw(md5_hex); use Hash::Util qw(lock_value unlock_hash lock_keys unlock_keys); +use List::MoreUtils qw(firstidx); use Safe; # Historical, needed for SCHEMA_VERSION = '1.00' use Storable qw(dclone freeze thaw); @@ -2451,7 +2452,7 @@ sub delete_column { my ($self, $table, $column) = @_; my $abstract_fields = $self->{abstract_schema}{$table}{FIELDS}; - my $name_position = lsearch($abstract_fields, $column); + my $name_position = firstidx { $_ eq $column } @$abstract_fields; die "Attempted to delete nonexistent column ${table}.${column}" if $name_position == -1; # Delete the key/value pair from the array. @@ -2540,7 +2541,7 @@ sub set_index { sub _set_object { my ($self, $table, $name, $definition, $array_to_change) = @_; - my $obj_position = lsearch($array_to_change, $name) + 1; + my $obj_position = (firstidx { $_ eq $name } @$array_to_change) + 1; # If the object doesn't exist, then add it. if (!$obj_position) { push(@$array_to_change, $name); @@ -2573,7 +2574,7 @@ sub delete_index { my ($self, $table, $name) = @_; my $indexes = $self->{abstract_schema}{$table}{INDEXES}; - my $name_position = lsearch($indexes, $name); + my $name_position = firstidx { $_ eq $name } @$indexes; die "Attempted to delete nonexistent index $name on the $table table" if $name_position == -1; # Delete the key/value pair from the array. diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm index 2513a19ae..b53abfb61 100644 --- a/Bugzilla/Field.pm +++ b/Bugzilla/Field.pm @@ -1154,8 +1154,8 @@ sub check_field { } if (!defined($value) - || trim($value) eq "" - || lsearch($legalsRef, $value) < 0) + or trim($value) eq "" + or !grep { $_ eq $value } @$legalsRef) { return 0 if $no_warn; # We don't want an error to be thrown; return. trick_taint($name); diff --git a/Bugzilla/Migrate/Gnats.pm b/Bugzilla/Migrate/Gnats.pm index 232100f2d..ff24f73b5 100644 --- a/Bugzilla/Migrate/Gnats.pm +++ b/Bugzilla/Migrate/Gnats.pm @@ -25,12 +25,13 @@ use base qw(Bugzilla::Migrate); use Bugzilla::Constants; use Bugzilla::Install::Util qw(indicate_progress); -use Bugzilla::Util qw(format_time trim generate_random_password lsearch); +use Bugzilla::Util qw(format_time trim generate_random_password); use Email::Address; use Email::MIME; use File::Basename; use IO::File; +use List::MoreUtils qw(firstidx); use List::Util qw(first); use constant REQUIRED_MODULES => [ @@ -168,14 +169,14 @@ use constant NON_COMMENT_FIELDS => qw( # we list out here the exact order of fields at the end of a PR # and wait for the next field to consider that we actually have # a field to parse. -use constant END_FIELD_ORDER => [qw( +use constant END_FIELD_ORDER => qw( Description How-To-Repeat Fix Release-Note Audit-Trail Unformatted -)]; +); use constant CUSTOM_FIELDS => { cf_type => { @@ -374,10 +375,12 @@ sub _get_gnats_field_data { # If this is one of the last few PR fields, then make sure # that we're getting our fields in the right order. my $new_field_valid = 1; - my $current_field_pos = - lsearch(END_FIELD_ORDER, $current_field || ''); + my $search_for = $current_field || ''; + my $current_field_pos = firstidx { $_ eq $search_for } + END_FIELD_ORDER; if ($current_field_pos > -1) { - my $new_field_pos = lsearch(END_FIELD_ORDER, $new_field); + my $new_field_pos = firstidx { $_ eq $new_field } + END_FIELD_ORDER; # We accept any field, as long as it's later than this one. $new_field_valid = $new_field_pos > $current_field_pos ? 1 : 0; } diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index da46774a1..a4e250cfc 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -55,6 +55,7 @@ use File::Find; use File::Path qw(rmtree mkpath); use File::Spec; use IO::Dir; +use List::MoreUtils qw(firstidx); use Scalar::Util qw(blessed); use base qw(Template); @@ -716,7 +717,10 @@ sub create { 'time2str' => \&Date::Format::time2str, # Generic linear search function - 'lsearch' => \&Bugzilla::Util::lsearch, + 'lsearch' => sub { + my ($array, $item) = @_; + return firstidx { $_ eq $item } @$array; + }, # Currently logged in user, if any # If an sudo session is in progress, this is the user we're faking diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 5c6209811..351dddfae 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -562,10 +562,11 @@ sub get_products_by_permission { # No need to go further if the user has no "special" privs. return [] unless scalar(@$product_ids); + my %product_map = map { $_ => 1 } @$product_ids; # We will restrict the list to products the user can see. my $selectable_products = $self->get_selectable_products; - my @products = grep {lsearch($product_ids, $_->id) > -1} @$selectable_products; + my @products = grep { $product_map{$_->id} } @$selectable_products; return \@products; } @@ -1490,7 +1491,7 @@ sub is_mover { if (!defined $self->{'is_mover'}) { my @movers = map { trim($_) } split(',', Bugzilla->params->{'movers'}); $self->{'is_mover'} = ($self->id - && lsearch(\@movers, $self->login) != -1); + && grep { $_ eq $self->login } @movers); } return $self->{'is_mover'}; } diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index de67d5a59..03826c143 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -36,7 +36,7 @@ use base qw(Exporter); html_quote url_quote xml_quote css_class_quote html_light_quote url_decode i_am_cgi correct_urlbase remote_ip - lsearch do_ssl_redirect_if_required use_attachbase + do_ssl_redirect_if_required use_attachbase diff_arrays trim wrap_hard wrap_comment find_wrap_point format_time format_time_decimal validate_date @@ -306,18 +306,6 @@ sub use_attachbase { && $attachbase ne Bugzilla->params->{'sslbase'}) ? 1 : 0; } -sub lsearch { - my ($list,$item) = (@_); - my $count = 0; - foreach my $i (@$list) { - if ($i eq $item) { - return $count; - } - $count++; - } - return -1; -} - sub diff_arrays { my ($old_ref, $new_ref) = @_; @@ -680,9 +668,6 @@ Bugzilla::Util - Generic utility functions for bugzilla my $is_cgi = i_am_cgi(); my $urlbase = correct_urlbase(); - # Functions for searching - $loc = lsearch(\@arr, $val); - # Data manipulation ($removed, $added) = diff_arrays(\@old, \@new); @@ -821,21 +806,6 @@ otherwise. =back -=head2 Searching - -Functions for searching within a set of values. - -=over 4 - -=item C<lsearch($list, $item)> - -Returns the position of C<$item> in C<$list>. C<$list> must be a list -reference. - -If the item is not in the list, returns -1. - -=back - =head2 Data Manipulation =over 4 |