Bug 75890 - Change lsearch() to grep()

git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@1362 6955db30-a419-402b-8a0d-67ecbb4d7f56
master
vfilippov 2011-09-05 13:46:57 +00:00
parent 445778a2f4
commit 05730a6b7f
9 changed files with 55 additions and 46 deletions

View File

@ -122,7 +122,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

View File

@ -144,7 +144,8 @@ 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 +155,8 @@ 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 +166,8 @@ 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 +177,8 @@ 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 +188,8 @@ 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 "";

View File

@ -1133,7 +1133,7 @@ sub check_field {
if (!defined($value)
|| trim($value) eq ""
|| lsearch($legalsRef, $value) < 0)
|| !grep { $_ eq $value } @$legalsRef)
{
return 0 if $no_warn; # We don't want an error to be thrown; return.
trick_taint($name);

View File

@ -577,7 +577,8 @@ sub get_products_by_permission {
# 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;
$product_ids = { map { $_ => 1 } @$product_ids };
my @products = grep { $product_ids->{$_->id} } @$selectable_products;
return \@products;
}
@ -1625,15 +1626,15 @@ sub wants_mail {
return defined($wants_mail) ? 1 : 0;
}
sub is_mover {
sub is_mover
{
my $self = shift;
if (!defined $self->{'is_mover'}) {
my @movers = map { trim($_) } split(',', Bugzilla->params->{'movers'});
$self->{'is_mover'} = ($self->id
&& lsearch(\@movers, $self->login) != -1);
if (!defined $self->{is_mover})
{
my @movers = map { trim($_) } split(',', Bugzilla->params->{movers});
$self->{is_mover} = $self->id && grep { $_ eq $self->login } @movers;
}
return $self->{'is_mover'};
return $self->{is_mover};
}
sub is_insider {

View File

@ -211,7 +211,7 @@ sub validateFormat
{
# receives a list of legal formats; first item is a default
my $format = $cgi->param('format') || $_[0];
if ( lsearch(\@_, $format) == -1)
if (!grep { $_ eq $format } @_)
{
ThrowUserError("invalid_format", { format => $format, formats => \@_ });
}

View File

@ -716,7 +716,7 @@ my @selectcolumns = ("bug_id", "bug_severity", "priority", "bug_status",
"resolution", "product");
# remaining and work_time are required for percentage_complete calculation:
if (lsearch(\@displaycolumns, "percentage_complete") >= 0) {
if (grep { $_ eq 'percentage_complete' } @displaycolumns) {
push (@selectcolumns, "remaining_time");
push (@selectcolumns, "work_time");
}
@ -986,14 +986,11 @@ $buglist_sth->execute();
# TODO перенести на общий механизм и чтобы в него вкручивалось interval_time
# If we're doing time tracking, then keep totals for all bugs.
my $percentage_complete = lsearch(\@displaycolumns, 'percentage_complete') >= 0;
my $estimated_time = lsearch(\@displaycolumns, 'estimated_time') >= 0;
my $remaining_time = ((lsearch(\@displaycolumns, 'remaining_time') >= 0)
|| $percentage_complete);
my $work_time = ((lsearch(\@displaycolumns, 'work_time') >= 0)
|| $percentage_complete);
my $interval_time = ((lsearch(\@displaycolumns, 'interval_time') >= 0)
|| $percentage_complete);
my $percentage_complete = 1 && grep { $_ eq 'percentage_complete' } @displaycolumns;
my $estimated_time = 1 && grep { $_ eq 'estimated_time' } @displaycolumns;
my $remaining_time = $percentage_complete || grep { $_ eq 'remaining_time' } @displaycolumns;
my $work_time = $percentage_complete || grep { $_ eq 'work_time' } @displaycolumns;
my $interval_time = $percentage_complete || grep { $_ eq 'interval_time' } @displaycolumns;
my $time_info = { 'estimated_time' => 0,
'remaining_time' => 0,

View File

@ -235,12 +235,12 @@ sub processCategoryChange {
push(@exclusions, $category) unless grep($_ eq $category, @exclusions);
}
elsif ($categoryAction eq 'removeInclusion') {
my @inclusion_to_remove = $cgi->param('inclusion_to_remove');
@inclusions = map {(lsearch(\@inclusion_to_remove, $_) < 0) ? $_ : ()} @inclusions;
my %rem = map { $_ => 1 } $cgi->param('inclusion_to_remove');
@inclusions = grep { !$rem{$_} } @inclusions;
}
elsif ($categoryAction eq 'removeExclusion') {
my @exclusion_to_remove = $cgi->param('exclusion_to_remove');
@exclusions = map {(lsearch(\@exclusion_to_remove, $_) < 0) ? $_ : ()} @exclusions;
my %rem = map { $_ => 1 } $cgi->param('exclusion_to_remove');
@exclusions = grep { !$rem{$_} } @exclusions;
}
# Convert the array @clusions('prod_ID:comp_ID') back to a hash of

View File

@ -561,20 +561,26 @@ else {
#
# Eventually maybe each product should have a "current version"
# parameter.
$vars->{'version'} = [map($_->name, @{$product->versions})];
$vars->{version} = [ map($_->name, @{$product->versions}) ];
if ( ($cloned_bug_id) &&
($product->name eq $cloned_bug->product ) ) {
my $vercookie = $cgi->cookie("VERSION-" . $product->name);
if ($cloned_bug_id && $product->name eq $cloned_bug->product)
{
$vars->{overridedefaultversion} = 1;
$default{'version'} = $cloned_bug->version;
} elsif (formvalue('version')) {
$default{version} = $cloned_bug->version;
}
elsif (formvalue('version'))
{
$vars->{overridedefaultversion} = 1;
$default{'version'} = formvalue('version');
} elsif (defined $cgi->cookie("VERSION-" . $product->name) &&
lsearch($vars->{'version'}, $cgi->cookie("VERSION-" . $product->name)) != -1) {
$default{'version'} = $cgi->cookie("VERSION-" . $product->name);
} else {
$default{'version'} = $vars->{'version'}->[$#{$vars->{'version'}}];
$default{version} = formvalue('version');
}
elsif (defined $vercookie && grep { $_ eq $vercookie } @{$vars->{version}})
{
$default{version} = $vercookie;
}
else
{
$default{version} = $vars->{version}->[$#{$vars->{'version'}}];
}
# Get list of milestones.
@ -607,17 +613,17 @@ unless ($has_editbugs || $has_canconfirm) {
@status = ($bug_status);
}
$vars->{'bug_status'} = \@status;
$vars->{bug_status} = \@status;
$vars->{resolution} = [ grep ($_, @{get_legal_field_values('resolution')}) ];
# Get the default from a template value if it is legitimate.
# Otherwise, and only if the user has privs, set the default
# to the first confirmed bug status on the list, if available.
if (formvalue('bug_status') && (lsearch(\@status, formvalue('bug_status')) >= 0)) {
$default{'bug_status'} = formvalue('bug_status');
} else {
$default{'bug_status'} = $status[0];
$default{bug_status} = formvalue('bug_status');
if (!grep { $_ eq $default{bug_status} } @status)
{
$default{bug_status} = $status[0];
}
my $grouplist = $dbh->selectall_arrayref(

View File

@ -435,7 +435,7 @@ sub post_bug
my $vers = [ map ($_->name, @{$product->versions}) ];
my $v;
if (($v = $cgi->cookie("VERSION-" . $product->name)) &&
(lsearch($vers, $v) != -1))
!grep { $_ eq $v } @$vers)
{
# возьмём из куки
$fields_in->{version} = $v;