diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2018-05-03 20:08:34 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2018-05-03 20:08:34 +0200 |
commit | 694442c766e1b469c62f87ef86c71a62826a1339 (patch) | |
tree | 36183128552d777853fd8db14075f0099bcdf455 /Cython/Utility/ModuleSetupCode.c | |
parent | eb0e46660cbbab70d4dcb53f94a4749ab261510b (diff) | |
download | cython-694442c766e1b469c62f87ef86c71a62826a1339.tar.gz |
Use dict versioning in Py3.6+ to reduce the overhead of checking for the "C-line in tracebacks" runtime option.
Diffstat (limited to 'Cython/Utility/ModuleSetupCode.c')
-rw-r--r-- | Cython/Utility/ModuleSetupCode.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c index 2aeabd2fe..fa2b62b41 100644 --- a/Cython/Utility/ModuleSetupCode.c +++ b/Cython/Utility/ModuleSetupCode.c @@ -79,6 +79,8 @@ #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 @@ -118,6 +120,8 @@ #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 #else #define CYTHON_COMPILING_IN_PYPY 0 @@ -181,6 +185,9 @@ #ifndef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif + #ifndef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #endif #endif #if !defined(CYTHON_FAST_PYCCALL) @@ -407,6 +414,23 @@ class __Pyx_FakeReference { #define __Pyx_PyFastCFunction_Check(func) 0 #endif +#if CYTHON_USE_DICT_VERSIONS +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) { \ + static PY_UINT64_T __pyx_dict_version = 0; \ + static PyObject *__pyx_dict_cached_value = NULL; \ + if (__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version) { \ + (VAR) = __pyx_dict_cached_value; \ + } else { \ + (VAR) = __pyx_dict_cached_value = (LOOKUP); \ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT); \ + } \ + } +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) #define PyObject_Malloc(s) PyMem_Malloc(s) #define PyObject_Free(p) PyMem_Free(p) |