[issue44283] Add jump table for certain safe match-case statements
Dennis Sweeney
report at bugs.python.org
Tue Jun 1 22:47:58 EDT 2021
Dennis Sweeney <sweeney.dennis650 at gmail.com> added the comment:
At first I thought of matches with only the int/str/None cases and then I saw the easy generalization, but yeah, each contiguous block seems better.
One solution to the code hashability/lookup speed apparent dilemma: writing the equivalent of this in C:
class HashableDict(dict):
def __new__(cls, pairs):
return dict.__new__(cls, pairs)
def __eq__(self, other):
return tuple(self.mapping.items()) == tuple(other.sequence.items())
def __hash__(self):
return CONSTANT ^ hash(tuple(self.items()))
def __getnewargs__(self):
return tuple(self.items())
# forbid all mutating methods
__setitem__ = __delitem__ = update = __ior__ = None # etc.
(Or maybe using composition rather than inheritence)
Maybe using the HAMT in /Python/hamt.c would suffice instead.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44283>
_______________________________________
More information about the Python-bugs-list
mailing list