From 715ea9ef3278c4ae358c41186f02ca43c08af001 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 11 Apr 2010 08:38:14 -0700 Subject: [PATCH] Speed up delete_jumps() Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Chains.pm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Chains.pm b/Shorewall/Perl/Shorewall/Chains.pm index 294ac41c0..5877298e7 100644 --- a/Shorewall/Perl/Shorewall/Chains.pm +++ b/Shorewall/Perl/Shorewall/Chains.pm @@ -673,23 +673,24 @@ sub add_jump( $$$;$$$ ) { # sub delete_jumps ( $$ ) { my ( $fromref, $toref ) = @_; - my $to = $toref->{name}; - my $last = 0; - my $rule; + my $to = $toref->{name}; + my $from = $fromref->{name}; + 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 # deleting elements from the array over which we are iterating. # - for ( $rule = 0; $rule <= $#{$fromref->{rules}}; $rule++ ) { - if ( $fromref->{rules}[$rule] =~ / -[gj] ${to}\b/ ) { + for ( my $rule = 0; $rule <= $#{$rules}; $rule++ ) { + if ( $rules->[$rule] =~ / -[gj] ${to}\b/ ) { trace( $fromref, 'D', $rule + 1, $_ ) if $debug; - splice( @{$fromref->{rules}}, $rule, 1 ); - last unless --$toref->{references}{$fromref->{name}} > 0; + splice( @$rules, $rule, 1 ); + last unless --$refs > 0; $rule--; } } - delete $toref->{references}{$fromref->{name}}; + delete $toref->{references}{$from}; unless ( @{$toref->{rules}} ) { $toref->{referenced} = 0;