Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/_speedups.c @ 611:db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 12 Jan 2022 01:04:24 +0100 |
| parents | 764d4185c76a |
| children | f797f798edfb |
line wrap: on
line diff
--- a/configmix/_speedups.c Wed Jan 12 00:44:02 2022 +0100 +++ b/configmix/_speedups.c Wed Jan 12 01:04:24 2022 +0100 @@ -37,7 +37,7 @@ }; -static PyObject * _fast_getvar_s(PyObject *, PyObject *, PyObject *, PyObject *, struct speedups_state *, int*); +static PyObject * _fast_getvar_s(PyObject *, PyObject *, PyObject *, struct speedups_state *, int*); static @@ -644,7 +644,7 @@ static PyObject * -fast_split_ns(PyObject *self, PyObject *varname) +_fast_split_ns(PyObject *varname, PyObject *self, struct speedups_state *sstate) { PyObject *res = NULL; Py_ssize_t ns_idx; @@ -679,7 +679,7 @@ Py_DECREF(res); return NULL; } - o2 = _fast_unquote(o1, ns_idx, self, NULL); + o2 = _fast_unquote(o1, ns_idx, self, sstate); if (o2 == NULL) { Py_DECREF(o1); Py_DECREF(res); @@ -699,6 +699,14 @@ static PyObject * +fast_split_ns(PyObject *self, PyObject *varname) +{ + return _fast_split_ns(varname, self, NULL); +} + + +static +PyObject * fast_interpolate_variables_old(PyObject *self, PyObject *args) { PyObject *config; @@ -840,7 +848,7 @@ filters = Py_NewRef(PyTuple_GetItem(tmp, 1)); py_clear_ref(&tmp); - varvalue = _fast_getvar_s(config, varname, NULL, self, sstate, &cacheable); + varvalue = _fast_getvar_s(config, varname, NULL, sstate, &cacheable); if (varvalue == NULL) { if (PyErr_ExceptionMatches(PyExc_KeyError)) { cacheable = 1; @@ -1057,7 +1065,7 @@ filters = Py_NewRef(PyTuple_GetItem(tmp, 1)); py_clear_ref(&tmp); - varvalue = _fast_getvar_s(config, varname, NULL, self, sstate, &cacheable); + varvalue = _fast_getvar_s(config, varname, NULL, sstate, &cacheable); if (varvalue == NULL) { if (PyErr_ExceptionMatches(PyExc_KeyError)) { @@ -1317,7 +1325,7 @@ */ static PyObject * -_fast_getvar_s(PyObject *config, PyObject *varname, PyObject *default_, PyObject *self, struct speedups_state *sstate, int *cacheable) +_fast_getvar_s(PyObject *config, PyObject *varname, PyObject *default_, struct speedups_state *sstate, int *cacheable) { PyObject *varname_b; /* always borrowed */ PyObject *namespace_b; /* always borrowed */ @@ -1326,7 +1334,7 @@ PyObject *tmp1; PyObject *tmp2; - splitted = fast_split_ns(self, varname); + splitted = _fast_split_ns(varname, NULL, sstate); if (splitted == NULL) { goto error; } @@ -1417,19 +1425,19 @@ return NULL; } - splitted = fast_split_ns(self, varname); + sstate = PyModule_GetState(self); + if (sstate == NULL) { + PyErr_SetString(PyExc_RuntimeError, "no module state available"); + return NULL; + } + + splitted = _fast_split_ns(varname, NULL, sstate); if (splitted == NULL) { goto error; } namespace_b = PyTuple_GetItem(splitted, 0); /* borrowed */ varname_b = PyTuple_GetItem(splitted, 1); /* borrowed */ - sstate = PyModule_GetState(self); - if (sstate == NULL) { - PyErr_SetString(PyExc_RuntimeError, "no module state available"); - goto error; - } - if (PyObject_Not(namespace_b)) { tmp1 = _fast_pathstr2path(varname_b, NULL, sstate); if (tmp1 == NULL) { @@ -1486,7 +1494,7 @@ PyErr_SetString(PyExc_RuntimeError, "no module state available"); return NULL; } - return _fast_getvar_s(config, varname, default_, self, sstate, &cacheable); + return _fast_getvar_s(config, varname, default_, sstate, &cacheable); }
