[pypy-svn] r17084 - pypy/dist/pypy/translator/c
arigo at codespeak.net
arigo at codespeak.net
Tue Aug 30 15:58:47 CEST 2005
Author: arigo
Date: Tue Aug 30 15:58:46 2005
New Revision: 17084
Modified:
pypy/dist/pypy/translator/c/gc.py
Log:
Use macros instead of repeating the code everywhere for incref/decref of
objects, based on the idea that the C preprocessor is faster than our Python
code producer and anyway having smaller .c files can't hurt. (Seems to save
10-20%.)
Modified: pypy/dist/pypy/translator/c/gc.py
==============================================================================
--- pypy/dist/pypy/translator/c/gc.py (original)
+++ pypy/dist/pypy/translator/c/gc.py Tue Aug 30 15:58:46 2005
@@ -88,18 +88,12 @@
def push_alive_nopyobj(self, expr, T):
defnode = self.db.gettypedefnode(T.TO)
if defnode.gcheader is not None:
- return 'if (%s) %s->%s++;' % (expr, expr, defnode.gcheader)
+ return 'pypy_IncRf_%s(%s);' % (defnode.barename, expr)
def pop_alive_nopyobj(self, expr, T):
defnode = self.db.gettypedefnode(T.TO)
if defnode.gcheader is not None:
- dealloc = 'OP_FREE'
- if defnode.gcinfo:
- dealloc = defnode.gcinfo.deallocator or dealloc
- return 'if (%s && !--%s->%s) %s(%s);' % (expr, expr,
- defnode.gcheader,
- dealloc,
- expr)
+ return 'pypy_DecRf_%s(%s);' % (defnode.barename, expr)
def push_alive_op_result(self, opname, expr, T):
if opname !='direct_call' and T != PyObjPtr:
@@ -144,6 +138,14 @@
gcinfo = defnode.gcinfo
if gcinfo.deallocator:
yield 'void %s(struct %s *);' % (gcinfo.deallocator, defnode.name)
+ if defnode.gcheader is not None:
+ dealloc = 'OP_FREE'
+ if defnode.gcinfo:
+ dealloc = defnode.gcinfo.deallocator or dealloc
+ yield '#define pypy_IncRf_%s(x) if (x) (x)->%s++' % (
+ defnode.barename, defnode.gcheader,)
+ yield '#define pypy_DecRf_%s(x) if ((x) && !--(x)->%s) %s(x)' % (
+ defnode.barename, defnode.gcheader, dealloc)
def common_gcheader_initializationexpr(self, defnode):
return 'REFCOUNT_IMMORTAL,'
More information about the Pypy-commit
mailing list