Commit d9ca179c authored by Xavier Thompson's avatar Xavier Thompson

Optimise runtime isolation check implementation

parent a505e7ef
......@@ -990,11 +990,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
namespace = entry.type.empty_declaration_code()
if templates_code:
code.putln(templates_code)
code.putln("int %s::CyObject_traverse_iso(void *(*visit)(const CyObject *o, void *arg), void *arg) const" % namespace)
code.putln("void %s::CyObject_traverse_iso(void (*visit)(const CyObject *o, void *arg), void *arg) const" % namespace)
code.putln("{")
for attr in check_cypclass_attrs:
code.putln("if (void *ret = visit(this->%s, arg)) return (int) (intptr_t) ret;" % attr.cname)
code.putln("return 0;")
code.putln("visit(this->%s, arg);" % attr.cname)
code.putln("}")
# isolation check method
if templates_code:
......@@ -1672,7 +1671,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# Declare the method to check isolation
code.putln("virtual int CyObject_iso() const;")
# Declare the traverse method
code.putln("virtual int CyObject_traverse_iso(void *(*visit)(const CyObject *o, void *arg), void *arg) const;")
code.putln("virtual void CyObject_traverse_iso(void (*visit)(const CyObject *o, void *arg), void *arg) const;")
if type.is_cyp_class and cypclass_attrs:
# Declaring a small destruction handler which will always try to Cy_XDECREF
......
......@@ -94,8 +94,8 @@
virtual int CyObject_iso() const {
return this->nogil_ob_refcnt == 1;
}
virtual int CyObject_traverse_iso(void *(*visit)(const CyObject *o, void *arg), void *arg) const {
return 0;
virtual void CyObject_traverse_iso(void (*visit)(const CyObject *o, void *arg), void *arg) const {
return;
}
/* Locking methods */
......@@ -489,28 +489,26 @@
/*
* Visit callback to collect reachable fields.
*/
static void *__Pyx_CyObject_visit_collect(const CyObject *ob, void *arg) {
static void __Pyx_CyObject_visit_collect(const CyObject *ob, void *arg) {
if (!ob)
return 0;
return;
if (ob->__refcnt)
return 0;
return;
ob->__refcnt = ob->CyObject_GETREF();
const CyObject *head = reinterpret_cast<CyObject *>(arg);
const CyObject *tmp = head->__next;
ob->__next = tmp;
head->__next = ob;
return 0;
}
/*
* Visit callback to decref reachable fields.
*/
static void *__Pyx_CyObject_visit_decref(const CyObject *ob, void *arg) {
static void __Pyx_CyObject_visit_decref(const CyObject *ob, void *arg) {
(void) arg;
if (!ob)
return 0;
return;
ob->__refcnt -= 1;
return 0;
}
/*
......
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