Commit b96c2f36 authored by Xavier Thompson's avatar Xavier Thompson

Avoid incref-ing and decref-ing around cypclass locks when possible

parent 39620fff
......@@ -14175,13 +14175,18 @@ class CoerceToLockedNode(CoercionNode):
# This node is used to lock a node of cypclass type around the evaluation of its subexpressions.
# rlock_only boolean
# needs_decref boolean used internally
def __init__(self, arg, env=None, rlock_only=False):
self.rlock_only = rlock_only
self.type = arg.type
arg = arg.coerce_to_temp(env)
arg.postpone_subexpr_disposal = True
super(CoerceToLockedNode,self).__init__(arg)
temp_arg = arg.coerce_to_temp(env)
temp_arg.postpone_subexpr_disposal = True
# Avoid incrementing the reference count when assigning to the temporary
# but ensure it will be decremented if it was already incremented previously.
self.needs_decref = not temp_arg.use_managed_ref
temp_arg.use_managed_ref = False
super(CoerceToLockedNode,self).__init__(temp_arg)
def result(self):
return self.arg.result()
......@@ -14219,8 +14224,12 @@ class CoerceToLockedNode(CoercionNode):
def generate_disposal_code(self, code):
# Close the scope to release the lock.
code.putln("}")
# Dispose of subexpressions.
super(CoerceToLockedNode,self).generate_disposal_code(code)
# Dispose of and free subexpressions.
self.arg.generate_subexpr_disposal_code(code)
self.arg.free_subexpr_temps(code)
# Decref only if previously incref-ed.
if self.needs_decref:
code.put_xdecref_clear(self.result(), self.ctype(), have_gil=not self.in_nogil_context)
class ProxyNode(CoercionNode):
......
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