]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Declare KEY_OBJECTS_ONLY as cdef variable
authorMatus Valo <Matus.Valo@solarturbines.com>
Sun, 26 Feb 2023 20:10:23 +0000 (15:10 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 27 Feb 2023 03:24:09 +0000 (22:24 -0500)
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

doc/build/changelog/unreleased_20/9343.rst [new file with mode: 0644]
lib/sqlalchemy/cyextension/resultproxy.pyx

diff --git a/doc/build/changelog/unreleased_20/9343.rst b/doc/build/changelog/unreleased_20/9343.rst
new file mode 100644 (file)
index 0000000..f6cf95e
--- /dev/null
@@ -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.
+
index e88c8ec0be870527ad176c842afd0061c15f7de5..96a028d93383481f96682581c9ccde534a8deb9c 100644 (file)
@@ -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)