Add __slots__ back to BaseNum subclasses

Slightly improves performance: Senate count from 8.22 to 7.63s
This commit is contained in:
RunasSudo 2021-01-19 02:22:39 +11:00
parent 53657677a3
commit 6f5ed93657
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
5 changed files with 10 additions and 0 deletions

View File

@ -168,6 +168,8 @@ class BaseNum:
class BasePyNum(BaseNum):
"""Helper class for Num wrappers of Python objects that already implement overloading"""
__slots__ = []
_py_class = None # Subclasses must specify
@classmethod

View File

@ -29,6 +29,8 @@ class Fixed(BasePyNum):
Wrapper for Python Decimal (for fixed-point arithmetic)
"""
__slots__ = []
_py_class = decimal.Decimal # For BasePyNum
ROUND_DOWN = decimal.ROUND_DOWN

View File

@ -34,6 +34,8 @@ class FixedGuarded(BasePyNum):
Implements guarded (quasi-exact) fixed-point
"""
__slots__ = []
_py_class = decimal.Decimal # For BasePyNum
ROUND_DOWN = decimal.ROUND_DOWN

View File

@ -23,6 +23,8 @@ class Native(BasePyNum):
Wrapper for Python float (naive floating-point arithmetic)
"""
__slots__ = []
_py_class = float # For BasePyNum
def round(self, dps, mode):

View File

@ -24,6 +24,8 @@ class Rational(BasePyNum):
Wrapper for Python Fraction (rational arithmetic)
"""
__slots__ = []
_py_class = Fraction # For BasePyNum
def pp(self, dp):