Avoid dict lookups when calling python callbacks

This commit is contained in:
Kovid Goyal 2017-09-06 21:04:31 +05:30
parent 6698712b44
commit b20367b888
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 2 additions and 2 deletions

View File

@ -330,7 +330,7 @@ render(ChildMonitor *self, double *timeout) {
double now = monotonic(); double now = monotonic();
double time_since_last_render = now - last_render_at; double time_since_last_render = now - last_render_at;
if (time_since_last_render > self->repaint_delay) { if (time_since_last_render > self->repaint_delay) {
ret = PyObject_CallObject(self->render_func, NULL); ret = PyObject_CallFunctionObjArgs(self->render_func, NULL);
if (ret == NULL) return false; if (ret == NULL) return false;
else Py_DECREF(ret); else Py_DECREF(ret);
glfwSwapBuffers(glfw_window_id); glfwSwapBuffers(glfw_window_id);

View File

@ -189,7 +189,7 @@ timers_call(Timers *self) {
for (i = 0, j = 0; i < self->count; i++) { for (i = 0, j = 0; i < self->count; i++) {
if (self->events[i].at <= now) { // expired, call it if (self->events[i].at <= now) { // expired, call it
if (self->events[i].callback != Py_None) { if (self->events[i].callback != Py_None) {
PyObject *ret = PyObject_CallObject(self->events[i].callback, self->events[i].args); PyObject *ret = self->events[i].args ? PyObject_CallObject(self->events[i].callback, self->events[i].args) : PyObject_CallFunctionObjArgs(self->events[i].callback, NULL);
if (ret == NULL) PyErr_Print(); if (ret == NULL) PyErr_Print();
else Py_DECREF(ret); else Py_DECREF(ret);
} }