Speed up delete_jumps()

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2010-04-11 08:38:14 -07:00
parent 91a711b34f
commit 715ea9ef32

View File

@ -674,22 +674,23 @@ sub add_jump( $$$;$$$ ) {
sub delete_jumps ( $$ ) { sub delete_jumps ( $$ ) {
my ( $fromref, $toref ) = @_; my ( $fromref, $toref ) = @_;
my $to = $toref->{name}; my $to = $toref->{name};
my $last = 0; my $from = $fromref->{name};
my $rule; my $rules = $fromref->{rules};
my $refs = $toref->{references}{$from};
# #
# A C-style for-loop with indexing seems to work best here, given that we are # A C-style for-loop with indexing seems to work best here, given that we are
# deleting elements from the array over which we are iterating. # deleting elements from the array over which we are iterating.
# #
for ( $rule = 0; $rule <= $#{$fromref->{rules}}; $rule++ ) { for ( my $rule = 0; $rule <= $#{$rules}; $rule++ ) {
if ( $fromref->{rules}[$rule] =~ / -[gj] ${to}\b/ ) { if ( $rules->[$rule] =~ / -[gj] ${to}\b/ ) {
trace( $fromref, 'D', $rule + 1, $_ ) if $debug; trace( $fromref, 'D', $rule + 1, $_ ) if $debug;
splice( @{$fromref->{rules}}, $rule, 1 ); splice( @$rules, $rule, 1 );
last unless --$toref->{references}{$fromref->{name}} > 0; last unless --$refs > 0;
$rule--; $rule--;
} }
} }
delete $toref->{references}{$fromref->{name}}; delete $toref->{references}{$from};
unless ( @{$toref->{rules}} ) { unless ( @{$toref->{rules}} ) {
$toref->{referenced} = 0; $toref->{referenced} = 0;