diff: Add slots to diff wrappers to reduce memory size.

For #127
This commit is contained in:
Chris PeBenito 2016-09-11 10:32:58 -04:00
parent 3f9a57521e
commit da87bfceb7
15 changed files with 45 additions and 2 deletions

View File

@ -95,6 +95,8 @@ class BoundsWrapper(Wrapper):
"""Wrap *bounds for diff purposes."""
__slots__ = ("ruletype", "parent", "child")
def __init__(self, rule):
self.origin = rule
self.ruletype = rule.ruletype

View File

@ -23,6 +23,8 @@ class ConditionalExprWrapper(Wrapper):
"""Wrap conditional policy expressions to allow comparisons by truth table."""
__slots__ = ("truth_table")
def __init__(self, cond):
self.origin = cond
self.truth_table = cond.truth_table()

View File

@ -186,6 +186,8 @@ class ConstraintWrapper(Wrapper):
"""Wrap constraints for diff purposes."""
__slots__ = ("ruletype", "tclass", "perms", "expr")
def __init__(self, rule):
self.origin = rule
self.ruletype = rule.ruletype

View File

@ -26,6 +26,8 @@ class ContextWrapper(Wrapper):
"""Wrap contexts to allow comparisons."""
__slots__ = ("user", "role", "type_", "range_")
def __init__(self, ctx):
self.origin = ctx
self.user = SymbolWrapper(ctx.user)

View File

@ -96,6 +96,8 @@ class DefaultWrapper(Wrapper):
"""Wrap default_* to allow comparisons."""
__slots__ = ("ruletype", "tclass")
def __init__(self, default):
self.origin = default
self.ruletype = default.ruletype

View File

@ -133,9 +133,10 @@ class Wrapper(object):
"""Base class for policy object wrappers."""
origin = None
__slots__ = ("origin", "key")
def __repr__(self):
# pylint: disable=no-member
return "<{0.__class__.__name__}(Wrapping {1})>".format(self, repr(self.origin))
def __hash__(self):
@ -159,12 +160,15 @@ class SymbolWrapper(Wrapper):
on its name.
"""
__slots__ = ("name")
def __init__(self, symbol):
self.origin = symbol
self.name = str(symbol)
self.key = hash(self.name)
def __hash__(self):
return hash(self.name)
return self.key
def __lt__(self, other):
return self.name < other.name

View File

@ -72,6 +72,8 @@ class FSUseWrapper(Wrapper):
"""Wrap fs_use_* rules to allow set operations."""
__slots__ = ("ruletype", "fs", "context")
def __init__(self, rule):
self.origin = rule
self.ruletype = rule.ruletype

View File

@ -72,6 +72,8 @@ class GenfsconWrapper(Wrapper):
"""Wrap genfscon rules to allow set operations."""
__slots__ = ("fs", "path", "filetype", "context")
def __init__(self, rule):
self.origin = rule
self.fs = rule.fs

View File

@ -169,6 +169,8 @@ class LevelDeclWrapper(Wrapper):
"""Wrap level declarations to allow comparisons."""
__slots__ = ("sensitivity")
def __init__(self, level):
self.origin = level
self.sensitivity = SymbolWrapper(level.sensitivity)
@ -190,6 +192,8 @@ class LevelWrapper(Wrapper):
"""Wrap levels to allow comparisons."""
__slots__ = ("sensitivity", "categories")
def __init__(self, level):
self.origin = level
self.sensitivity = SymbolWrapper(level.sensitivity)
@ -215,6 +219,8 @@ class RangeWrapper(Wrapper):
to levels between the low and high levels of the range.
"""
__slots__ = ("low", "high")
def __init__(self, range_):
self.origin = range_
self.low = LevelWrapper(range_.low)

View File

@ -104,6 +104,8 @@ class MLSRuleWrapper(Wrapper):
"""Wrap MLS rules to allow set operations."""
__slots__ = ("ruletype", "source", "target", "tclass")
def __init__(self, rule):
self.origin = rule
self.ruletype = rule.ruletype

View File

@ -87,6 +87,8 @@ class NetifconWrapper(Wrapper):
"""Wrap netifcon statements for diff purposes."""
__slots__ = ("netif")
def __init__(self, ocon):
self.origin = ocon
self.netif = ocon.netif

View File

@ -71,6 +71,8 @@ class NodeconWrapper(Wrapper):
"""Wrap nodecon statements for diff purposes."""
__slots__ = ("ip_version", "address", "netmask")
def __init__(self, ocon):
self.origin = ocon
self.ip_version = ocon.ip_version

View File

@ -71,6 +71,8 @@ class PortconWrapper(Wrapper):
"""Wrap portcon statements for diff purposes."""
__slots__ = ("protocol", "low", "high")
def __init__(self, ocon):
self.origin = ocon
self.protocol = ocon.protocol

View File

@ -123,6 +123,8 @@ class RoleAllowWrapper(Wrapper):
"""Wrap role allow rules to allow set operations."""
__slots__ = ("ruletype", "source", "target")
def __init__(self, rule):
self.origin = rule
self.ruletype = rule.ruletype
@ -146,6 +148,8 @@ class RoleTransitionWrapper(Wrapper):
"""Wrap role_transition rules to allow set operations."""
__slots__ = ("ruletype", "source", "target", "tclass")
def __init__(self, rule):
self.origin = rule
self.ruletype = rule.ruletype

View File

@ -297,6 +297,8 @@ class AVRuleWrapper(Wrapper):
"""Wrap access vector rules to allow set operations."""
__slots__ = ("ruletype", "source", "target", "tclass", "conditional", "conditional_block")
def __init__(self, rule):
self.origin = rule
self.ruletype = rule.ruletype
@ -332,6 +334,8 @@ class AVRuleXpermWrapper(Wrapper):
"""Wrap extended permission access vector rules to allow set operations."""
__slots__ = ("ruletype", "source", "target", "tclass", "xperm_type")
def __init__(self, rule):
self.origin = rule
self.ruletype = rule.ruletype
@ -360,6 +364,9 @@ class TERuleWrapper(Wrapper):
"""Wrap type_* rules to allow set operations."""
__slots__ = ("ruletype", "source", "target", "tclass", "conditional", "conditional_block",
"filename")
def __init__(self, rule):
self.origin = rule
self.ruletype = rule.ruletype