Small optimization

This commit is contained in:
Kovid Goyal 2015-06-19 13:49:48 +05:30
parent 6f09a10380
commit 810f9ac2f9

View File

@ -99,21 +99,20 @@ static PyObject *DukContext_eval(DukContext *self, PyObject *args, PyObject *kw)
if (temp && PyObject_IsTrue(temp)) noresult = 1; if (temp && PyObject_IsTrue(temp)) noresult = 1;
self->py_thread_state = PyEval_SaveThread(); // Release GIL self->py_thread_state = PyEval_SaveThread(); // Release GIL
ret = duk_peval_string(self->ctx, code); ret = (noresult) ? duk_peval_string_noresult(self->ctx, code) : duk_peval_string(self->ctx, code);
PyEval_RestoreThread(self->py_thread_state); // Acquire GIL PyEval_RestoreThread(self->py_thread_state); // Acquire GIL
self->py_thread_state = NULL; self->py_thread_state = NULL;
if (ret != 0) { if (ret != 0) {
temp = duk_to_python(self->ctx, -1); temp = duk_to_python(self->ctx, -1);
duk_pop(self->ctx);
if (temp) { if (temp) {
PyErr_SetObject(JSError, temp); PyErr_SetObject(JSError, temp);
Py_DECREF(temp); Py_DECREF(temp);
} } else PyErr_SetString(PyExc_RuntimeError, "The was an error during eval(), but the error could not be read of the stack");
duk_pop(self->ctx);
return NULL; return NULL;
} }
if (noresult) { if (noresult) {
duk_pop(self->ctx);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -137,21 +136,20 @@ static PyObject *DukContext_eval_file(DukContext *self, PyObject *args, PyObject
if (temp && PyObject_IsTrue(temp)) noresult = 1; if (temp && PyObject_IsTrue(temp)) noresult = 1;
self->py_thread_state = PyEval_SaveThread(); // Release GIL self->py_thread_state = PyEval_SaveThread(); // Release GIL
ret = duk_peval_file(self->ctx, path); ret = (noresult) ? duk_peval_file_noresult(self->ctx, path) : duk_peval_file(self->ctx, path);
PyEval_RestoreThread(self->py_thread_state); // Acquire GIL PyEval_RestoreThread(self->py_thread_state); // Acquire GIL
self->py_thread_state = NULL; self->py_thread_state = NULL;
if (ret != 0) { if (ret != 0) {
temp = duk_to_python(self->ctx, -1); temp = duk_to_python(self->ctx, -1);
duk_pop(self->ctx);
if (temp) { if (temp) {
PyErr_SetObject(JSError, temp); PyErr_SetObject(JSError, temp);
Py_DECREF(temp); Py_DECREF(temp);
} } else PyErr_SetString(PyExc_RuntimeError, "The was an error during eval_file(), but the error could not be read of the stack");
duk_pop(self->ctx);
return NULL; return NULL;
} }
if (noresult) { if (noresult) {
duk_pop(self->ctx);
Py_RETURN_NONE; Py_RETURN_NONE;
} }