Add __slots__ back to BaseNum subclasses
Slightly improves performance: Senate count from 8.22 to 7.63s
This commit is contained in:
parent
53657677a3
commit
6f5ed93657
@ -168,6 +168,8 @@ class BaseNum:
|
|||||||
class BasePyNum(BaseNum):
|
class BasePyNum(BaseNum):
|
||||||
"""Helper class for Num wrappers of Python objects that already implement overloading"""
|
"""Helper class for Num wrappers of Python objects that already implement overloading"""
|
||||||
|
|
||||||
|
__slots__ = []
|
||||||
|
|
||||||
_py_class = None # Subclasses must specify
|
_py_class = None # Subclasses must specify
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -29,6 +29,8 @@ class Fixed(BasePyNum):
|
|||||||
Wrapper for Python Decimal (for fixed-point arithmetic)
|
Wrapper for Python Decimal (for fixed-point arithmetic)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = []
|
||||||
|
|
||||||
_py_class = decimal.Decimal # For BasePyNum
|
_py_class = decimal.Decimal # For BasePyNum
|
||||||
|
|
||||||
ROUND_DOWN = decimal.ROUND_DOWN
|
ROUND_DOWN = decimal.ROUND_DOWN
|
||||||
|
@ -34,6 +34,8 @@ class FixedGuarded(BasePyNum):
|
|||||||
Implements guarded (quasi-exact) fixed-point
|
Implements guarded (quasi-exact) fixed-point
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = []
|
||||||
|
|
||||||
_py_class = decimal.Decimal # For BasePyNum
|
_py_class = decimal.Decimal # For BasePyNum
|
||||||
|
|
||||||
ROUND_DOWN = decimal.ROUND_DOWN
|
ROUND_DOWN = decimal.ROUND_DOWN
|
||||||
|
@ -23,6 +23,8 @@ class Native(BasePyNum):
|
|||||||
Wrapper for Python float (naive floating-point arithmetic)
|
Wrapper for Python float (naive floating-point arithmetic)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = []
|
||||||
|
|
||||||
_py_class = float # For BasePyNum
|
_py_class = float # For BasePyNum
|
||||||
|
|
||||||
def round(self, dps, mode):
|
def round(self, dps, mode):
|
||||||
|
@ -24,6 +24,8 @@ class Rational(BasePyNum):
|
|||||||
Wrapper for Python Fraction (rational arithmetic)
|
Wrapper for Python Fraction (rational arithmetic)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = []
|
||||||
|
|
||||||
_py_class = Fraction # For BasePyNum
|
_py_class = Fraction # For BasePyNum
|
||||||
|
|
||||||
def pp(self, dp):
|
def pp(self, dp):
|
||||||
|
Reference in New Issue
Block a user