Replace the complex rule deletion loops with C-stype for loops.

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2010-04-09 09:58:32 -07:00
parent 9dc8267888
commit 7a831107c7

View File

@ -601,29 +601,13 @@ sub purge_jump ( $$ ) {
my ( $fromref, $toref ) = @_; my ( $fromref, $toref ) = @_;
my $to = $toref->{name}; my $to = $toref->{name};
my $last = 0; my $last = 0;
# my $rule;
# splice() of an array being iterated over causes elements to be skipped so
# we need to restart the scan after each deletion.
#
my $progress = 1;
while ( $progress ) { for ( $rule = 0; $rule < $#{$fromref->{rules}}; $rule++ ) {
my $rule = 0; if ( $fromref->{rules}[$rule] =~ / -[gj] ${to}\b/ ) {
trace( $fromref, 'D', $rule + 1, $_ ) if $debug;
$progress = 0; splice( @{$fromref->{rules}}, $rule, 1 );
$rule--;
for ( @{$fromref->{rules}} ) {
$rule++, next if $last-- > 0;
if ( / -[gj] ${to}\b/ ) {
trace( $fromref, 'D', $rule + 1, $_ ) if $debug;
splice( @{$fromref->{rules}}, $rule, 1 );
$progress = 1;
$last = $rule;
last;
}
$rule++;
} }
} }
@ -1433,33 +1417,15 @@ sub delete_references( $ ) {
my $chainref = shift; my $chainref = shift;
my $table = $chainref->{table}; my $table = $chainref->{table};
my $count = 0; my $count = 0;
my $last = 0; my $rule;
for my $fromref ( map $chain_table{$table}{$_} , keys %{$chainref->{references}} ) { for my $fromref ( map $chain_table{$table}{$_} , keys %{$chainref->{references}} ) {
# for ( $rule = 0; $rule <= $#{$fromref->{rules}}; $rule++ ) {
# splice() of an array being iterated over causes elements to be skipped so if ( $fromref->{rules}[$rule] =~ / -[jg] $chainref->{name}$/ ) {
# we need to restart the scan after each deletion. trace( $fromref, 'D', $rule + 1, $_ ) if $debug;
# splice( @{$fromref->{rules}}, $rule, 1 );
my $progress = 1; $count++;
$rule--;
while ( $progress ) {
my $rule = 0;
$progress = 0;
for ( @{$fromref->{rules}} ) {
$rule++, next if $last-- > 0;
if ( / -[jg] $chainref->{name}$/ ) {
trace( $fromref, 'D', $rule + 1, $_ ) if $debug;
splice( @{$fromref->{rules}}, $rule, 1 );
$count++;
$progress = 1;
$last = $rule;
last;
}
$rule++;
} }
} }