summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/traversals.py
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-12-27 15:26:31 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-12-27 15:26:31 +0000
commit4a12848a1cf47ed43c93c5ee8029b644242d0a17 (patch)
tree233c3862dc5734becb9ed2d9cf7f95a71382de77 /lib/sqlalchemy/sql/traversals.py
parent2bb6cfc7c9b8f09eaa4efeffc337a1162993979c (diff)
parente6cd36fc51d25922f20aa203229a636f5d6daabe (diff)
downloadsqlalchemy-4a12848a1cf47ed43c93c5ee8029b644242d0a17.tar.gz
Merge "implement cython for cache_anon_map, prefix_anon_map" into main
Diffstat (limited to 'lib/sqlalchemy/sql/traversals.py')
-rw-r--r--lib/sqlalchemy/sql/traversals.py38
1 files changed, 9 insertions, 29 deletions
diff --git a/lib/sqlalchemy/sql/traversals.py b/lib/sqlalchemy/sql/traversals.py
index 12a5486d2..b689fe578 100644
--- a/lib/sqlalchemy/sql/traversals.py
+++ b/lib/sqlalchemy/sql/traversals.py
@@ -12,6 +12,12 @@ from .. import util
from ..inspection import inspect
from ..util import HasMemoized
+try:
+ from sqlalchemy.cyextension.util import cache_anon_map as anon_map # noqa
+except ImportError:
+ from ._py_util import cache_anon_map as anon_map # noqa
+
+
SKIP_TRAVERSE = util.symbol("skip_traverse")
COMPARE_FAILED = False
COMPARE_SUCCEEDED = True
@@ -177,16 +183,11 @@ class HasCacheKey:
"""
- idself = id(self)
cls = self.__class__
- if idself in anon_map:
- return (anon_map[idself], cls)
- else:
- # inline of
- # id_ = anon_map[idself]
- anon_map[idself] = id_ = str(anon_map.index)
- anon_map.index += 1
+ id_, found = anon_map.get_anon(self)
+ if found:
+ return (id_, cls)
try:
dispatcher = cls.__dict__["_generated_cache_key_traversal"]
@@ -1029,27 +1030,6 @@ def _resolve_name_for_compare(element, name, anon_map, **kw):
return name
-class anon_map(dict):
- """A map that creates new keys for missing key access.
-
- Produces an incrementing sequence given a series of unique keys.
-
- This is similar to the compiler prefix_anon_map class although simpler.
-
- Inlines the approach taken by :class:`sqlalchemy.util.PopulateDict` which
- is otherwise usually used for this type of operation.
-
- """
-
- def __init__(self):
- self.index = 0
-
- def __missing__(self, key):
- self[key] = val = str(self.index)
- self.index += 1
- return val
-
-
class TraversalComparatorStrategy(InternalTraversal, util.MemoizedSlots):
__slots__ = "stack", "cache", "anon_map"