bpo-32436: Make PyContextVar_Get a little bit faster (#5350)
authorYury Selivanov <yury@magic.io>
Fri, 26 Jan 2018 22:24:52 +0000 (17:24 -0500)
committerGitHub <noreply@github.com>
Fri, 26 Jan 2018 22:24:52 +0000 (17:24 -0500)
Since context.c is compiled with Py_BUILD_CORE, using a macro
will result in a slightly more optimal code.

Python/context.c

index d90ed25c4d4068152583a8ebbba93516a72d35d8..3928e94d06453826d45a68742fe5eaff10017c27 100644 (file)
@@ -145,7 +145,8 @@ PyContextVar_Get(PyContextVar *var, PyObject *def, PyObject **val)
 {
     assert(PyContextVar_CheckExact(var));
 
-    PyThreadState *ts = PyThreadState_Get();
+    PyThreadState *ts = PyThreadState_GET();
+    assert(ts != NULL);
     if (ts->context == NULL) {
         goto not_found;
     }