[pypy-commit] pypy default: (sbehnel) cpyext: Inline the fast path of Py_INCREF and Py_DECREF,
amauryfa
noreply at buildbot.pypy.org
Mon Apr 23 23:59:27 CEST 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r54699:0feb5408579b
Date: 2012-04-23 23:56 +0200
http://bitbucket.org/pypy/pypy/changeset/0feb5408579b/
Log: (sbehnel) cpyext: Inline the fast path of Py_INCREF and Py_DECREF,
to avoid costly function calls.
diff --git a/pypy/module/cpyext/include/object.h b/pypy/module/cpyext/include/object.h
--- a/pypy/module/cpyext/include/object.h
+++ b/pypy/module/cpyext/include/object.h
@@ -38,10 +38,19 @@
PyObject_VAR_HEAD
} PyVarObject;
+#ifndef PYPY_DEBUG_REFCOUNT
#define Py_INCREF(ob) (Py_IncRef((PyObject *)ob))
#define Py_DECREF(ob) (Py_DecRef((PyObject *)ob))
#define Py_XINCREF(ob) (Py_IncRef((PyObject *)ob))
#define Py_XDECREF(ob) (Py_DecRef((PyObject *)ob))
+#else
+#define Py_INCREF(ob) (((PyObject *)ob)->ob_refcnt++)
+#define Py_DECREF(ob) ((((PyObject *)ob)->ob_refcnt > 1) ? \
+ ((PyObject *)ob)->ob_refcnt-- : (Py_DecRef((PyObject *)ob)))
+
+#define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
+#define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
+#endif
#define Py_CLEAR(op) \
do { \
More information about the pypy-commit
mailing list