Speed-up iptables_manager remove_chain() code
remove_chain() has three list iterations that can be reduced to two, brings a small performance increase. Change-Id: I6f6e05b2336a983062f4787cb933d56fdf71a90a Partial-bug: #1642770
This commit is contained in:
parent
310f83bc4e
commit
5ff8aecefb
|
@ -183,24 +183,18 @@ class IptablesTable(object):
|
|||
# so we keep a list of them to be iterated over in apply()
|
||||
self.remove_chains.add(name)
|
||||
|
||||
# first, add rules to remove that have a matching chain name
|
||||
self.remove_rules += [str(r) for r in self.rules
|
||||
if r.chain == name]
|
||||
|
||||
# next, remove rules from list that have a matching chain name
|
||||
self.rules = [r for r in self.rules if r.chain != name]
|
||||
|
||||
if not wrap:
|
||||
# Add rules to remove that have a matching chain name or
|
||||
# a matching jump chain
|
||||
jump_snippet = '-j %s' % name
|
||||
# next, add rules to remove that have a matching jump chain
|
||||
self.remove_rules += [str(r) for r in self.rules
|
||||
if jump_snippet in r.rule]
|
||||
if r.chain == name or jump_snippet in r.rule]
|
||||
else:
|
||||
jump_snippet = '-j %s-%s' % (self.wrap_name, name)
|
||||
|
||||
# finally, remove rules from list that have a matching jump chain
|
||||
# Remove rules from list that have a matching chain name or
|
||||
# a matching jump chain
|
||||
self.rules = [r for r in self.rules
|
||||
if jump_snippet not in r.rule]
|
||||
if r.chain != name and jump_snippet not in r.rule]
|
||||
|
||||
def add_rule(self, chain, rule, wrap=True, top=False, tag=None,
|
||||
comment=None):
|
||||
|
|
Loading…
Reference in New Issue