Commit d2b46ecc authored by Stefan Behnel's avatar Stefan Behnel

extend freelist support to all subtypes that have the same object struct size

parent 11e3944a
...@@ -1065,8 +1065,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1065,8 +1065,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else: else:
code.putln("PyObject *o;") code.putln("PyObject *o;")
if freelist_size: if freelist_size:
code.putln("if ((%s > 0) & (t == %s)) {" % ( code.putln("if ((%s > 0) & (t->tp_basicsize == sizeof(%s))) {" % (
freecount_name, type.typeptr_cname)) freecount_name, type.declaration_code("", deref=True)))
code.putln("o = (PyObject*)%s[--%s];" % ( code.putln("o = (PyObject*)%s[--%s];" % (
freelist_name, freecount_name)) freelist_name, freecount_name))
code.putln("PyObject_INIT(o, t);") code.putln("PyObject_INIT(o, t);")
...@@ -1208,8 +1208,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1208,8 +1208,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
freecount_name = scope.mangle_internal(Naming.freecount_name) freecount_name = scope.mangle_internal(Naming.freecount_name)
type = scope.parent_type type = scope.parent_type
code.putln("if ((%s < %d) & (Py_TYPE(o) == %s)) {" % ( code.putln("if ((%s < %d) & (Py_TYPE(o)->tp_basicsize == sizeof(%s))) {" % (
freecount_name, freelist_size, type.typeptr_cname)) freecount_name, freelist_size, type.declaration_code("", deref=True)))
code.putln("%s[%s++] = %s;" % ( code.putln("%s[%s++] = %s;" % (
freelist_name, freecount_name, type.cast_code("o"))) freelist_name, freecount_name, type.cast_code("o")))
code.putln("} else {") code.putln("} else {")
......
...@@ -43,6 +43,17 @@ def tpnew_ExtTypeWithGC(): ...@@ -43,6 +43,17 @@ def tpnew_ExtTypeWithGC():
return ExtTypeWithGC.__new__(ExtTypeWithGC) return ExtTypeWithGC.__new__(ExtTypeWithGC)
cdef class ExtSubType(ExtTypeWithGC):
"""
>>> obj = ExtSubType()
>>> obj = ExtSubType()
>>> obj = ExtSubType()
>>> obj = ExtSubType()
>>> obj = ExtSubType()
>>> obj = ExtSubType()
"""
@cython.freelist(8) @cython.freelist(8)
cdef class ExtTypeWithRefCycle: cdef class ExtTypeWithRefCycle:
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment