utils.gen: set __slots__.

We create *a lot* of these structs, so it saves a considerable
amount of space.
This commit is contained in:
Valentin Lorentz 2020-05-15 22:57:35 +02:00
parent 0bfd82f650
commit eead5566e5
2 changed files with 4 additions and 1 deletions

View File

@ -688,7 +688,7 @@ class DuplicateHostmask(ValueError):
class UsersDictionary(utils.IterableMap): class UsersDictionary(utils.IterableMap):
"""A simple serialized-to-file User Database.""" """A simple serialized-to-file User Database."""
__slots__ = ('noFlush', 'filename', 'users', '_nameCache', __slots__ = ('noFlush', 'filename', 'users', '_nameCache',
'_hostmaskCache') '_hostmaskCache', 'nextId')
def __init__(self): def __init__(self):
self.noFlush = False self.noFlush = False
self.filename = None self.filename = None

View File

@ -219,6 +219,7 @@ def exnToString(e):
class IterableMap(object): class IterableMap(object):
"""Define .items() in a class and subclass this to get the other iters. """Define .items() in a class and subclass this to get the other iters.
""" """
__slots__ = ()
def items(self): def items(self):
if minisix.PY3 and hasattr(self, 'iteritems'): if minisix.PY3 and hasattr(self, 'iteritems'):
# For old plugins # For old plugins
@ -252,6 +253,7 @@ class IterableMap(object):
class InsensitivePreservingDict(collections.abc.MutableMapping): class InsensitivePreservingDict(collections.abc.MutableMapping):
__slots__ = ('data',)
def key(self, s): def key(self, s):
"""Override this if you wish.""" """Override this if you wish."""
if s is not None: if s is not None:
@ -307,6 +309,7 @@ class InsensitivePreservingDict(collections.abc.MutableMapping):
class NormalizingSet(set): class NormalizingSet(set):
__slots__ = ()
def __init__(self, iterable=()): def __init__(self, iterable=()):
iterable = list(map(self.normalize, iterable)) iterable = list(map(self.normalize, iterable))
super(NormalizingSet, self).__init__(iterable) super(NormalizingSet, self).__init__(iterable)