Commit 5d0d221d authored by Xavier Thompson's avatar Xavier Thompson

Optimise runtime 'iso' check for 'active' and 'locked' instances

parent c329db8f
...@@ -11378,6 +11378,7 @@ class ConsumeNode(ExprNode): ...@@ -11378,6 +11378,7 @@ class ConsumeNode(ExprNode):
# #
# nogil boolean used internally # nogil boolean used internally
# generate_runtime_check boolean used internally # generate_runtime_check boolean used internally
# check_refcount_only boolean used internally
# operand_is_named boolean used internally # operand_is_named boolean used internally
subexprs = ['operand'] subexprs = ['operand']
...@@ -11405,12 +11406,14 @@ class ConsumeNode(ExprNode): ...@@ -11405,12 +11406,14 @@ class ConsumeNode(ExprNode):
self.type = PyrexTypes.error_type self.type = PyrexTypes.error_type
return self return self
self.generate_runtime_check = operand_type.qualifier not in ('iso', 'iso~') self.generate_runtime_check = operand_type.qualifier not in ('iso', 'iso~')
self.check_refcount_only = operand_type.qualifier in ('active', 'locked')
if operand_type.qualifier == 'iso~': if operand_type.qualifier == 'iso~':
self.type = operand_type self.type = operand_type
else: else:
self.type = PyrexTypes.cyp_class_qualified_type(operand_type.qual_base_type, 'iso~') self.type = PyrexTypes.cyp_class_qualified_type(operand_type.qual_base_type, 'iso~')
else: else:
self.generate_runtime_check = True self.generate_runtime_check = True
self.check_refcount_only = False
self.type = PyrexTypes.cyp_class_qualified_type(operand_type, 'iso~') self.type = PyrexTypes.cyp_class_qualified_type(operand_type, 'iso~')
self.operand_is_named = self.operand.is_name or self.operand.is_attribute self.operand_is_named = self.operand.is_name or self.operand.is_attribute
self.is_temp = self.operand_is_named or (self.generate_runtime_check and not self.operand.is_temp) self.is_temp = self.operand_is_named or (self.generate_runtime_check and not self.operand.is_temp)
...@@ -11441,7 +11444,10 @@ class ConsumeNode(ExprNode): ...@@ -11441,7 +11444,10 @@ class ConsumeNode(ExprNode):
if self.is_temp: if self.is_temp:
code.putln("%s = %s;" % (result_code, self.operand.result())) code.putln("%s = %s;" % (result_code, self.operand.result()))
if self.generate_runtime_check: if self.generate_runtime_check:
code.putln("if (%s != NULL && !%s->CyObject_iso()) {" % (result_code, result_code)) if self.check_refcount_only:
code.putln("if (%s != NULL && %s->CyObject_GETREF() != 1) {" % (result_code, result_code))
else:
code.putln("if (%s != NULL && !%s->CyObject_iso()) {" % (result_code, result_code))
if self.nogil: if self.nogil:
code.putln("#ifdef WITH_THREAD") code.putln("#ifdef WITH_THREAD")
code.putln("PyGILState_STATE _save = PyGILState_Ensure();") code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
......
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