From: Matus Valo Date: Sun, 26 Feb 2023 20:10:23 +0000 (-0500) Subject: Declare KEY_OBJECTS_ONLY as cdef variable X-Git-Tag: rel_2_0_5~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1d94b673be5e0121e657b0b368f186197072574;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Declare KEY_OBJECTS_ONLY as cdef variable A small optimization to the Cython implementation of :class:`.ResultProxy` using a cdef for a particular int value to avoid Python overhead. Pull request courtesy Matus Valo. Fixes: #9343 Closes: #9344 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9344 Pull-request-sha: fc6a97debe45497ef502f3861611b021a5885b63 Change-Id: I231d4fb292decfe9bccdf54f2851ce6f69d5d6c7 --- diff --git a/doc/build/changelog/unreleased_20/9343.rst b/doc/build/changelog/unreleased_20/9343.rst new file mode 100644 index 0000000000..f6cf95e13c --- /dev/null +++ b/doc/build/changelog/unreleased_20/9343.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: engine, performance + :tickets: 9343 + + A small optimization to the Cython implementation of :class:`.ResultProxy` + using a cdef for a particular int value to avoid Python overhead. Pull + request courtesy Matus Valo. + diff --git a/lib/sqlalchemy/cyextension/resultproxy.pyx b/lib/sqlalchemy/cyextension/resultproxy.pyx index e88c8ec0be..96a028d933 100644 --- a/lib/sqlalchemy/cyextension/resultproxy.pyx +++ b/lib/sqlalchemy/cyextension/resultproxy.pyx @@ -3,9 +3,10 @@ import operator cdef int MD_INDEX = 0 # integer index in cursor.description +cdef int _KEY_OBJECTS_ONLY = 1 KEY_INTEGER_ONLY = 0 -KEY_OBJECTS_ONLY = 1 +KEY_OBJECTS_ONLY = _KEY_OBJECTS_ONLY cdef class BaseRow: cdef readonly object _parent @@ -76,7 +77,7 @@ cdef class BaseRow: if mdindex is None: self._parent._raise_for_ambiguous_column_name(rec) elif ( - self._key_style == KEY_OBJECTS_ONLY + self._key_style == _KEY_OBJECTS_ONLY and isinstance(key, int) ): raise KeyError(key)