Commit 630d0edd authored by Mark Florisson's avatar Mark Florisson

Don't decref slices on first assignment

parent d93be9df
...@@ -1816,7 +1816,8 @@ class NameNode(AtomicExprNode): ...@@ -1816,7 +1816,8 @@ class NameNode(AtomicExprNode):
lhs_pos=self.pos, lhs_pos=self.pos,
rhs=rhs, rhs=rhs,
code=code, code=code,
have_gil=not self.in_nogil_context) have_gil=not self.in_nogil_context,
first_assignment=self.cf_is_null)
def generate_acquire_buffer(self, rhs, code): def generate_acquire_buffer(self, rhs, code):
# rhstmp is only used in case the rhs is a complicated expression leading to # rhstmp is only used in case the rhs is a complicated expression leading to
......
...@@ -81,7 +81,8 @@ def mangle_dtype_name(dtype): ...@@ -81,7 +81,8 @@ def mangle_dtype_name(dtype):
# return "".join([access[0].upper()+packing[0] for (access, packing) in axes]) # return "".join([access[0].upper()+packing[0] for (access, packing) in axes])
def put_acquire_memoryviewslice(lhs_cname, lhs_type, lhs_pos, rhs, code, def put_acquire_memoryviewslice(lhs_cname, lhs_type, lhs_pos, rhs, code,
have_gil=False): have_gil=False, first_assignment=True):
"We can avoid decreffing the lhs if we know it is the first assignment"
assert rhs.type.is_memoryviewslice assert rhs.type.is_memoryviewslice
pretty_rhs = isinstance(rhs, NameNode) or rhs.result_in_temp() pretty_rhs = isinstance(rhs, NameNode) or rhs.result_in_temp()
...@@ -94,14 +95,16 @@ def put_acquire_memoryviewslice(lhs_cname, lhs_type, lhs_pos, rhs, code, ...@@ -94,14 +95,16 @@ def put_acquire_memoryviewslice(lhs_cname, lhs_type, lhs_pos, rhs, code,
# Allow uninitialized assignment # Allow uninitialized assignment
#code.putln(code.put_error_if_unbound(lhs_pos, rhs.entry)) #code.putln(code.put_error_if_unbound(lhs_pos, rhs.entry))
put_assign_to_memviewslice(lhs_cname, rhs, rhstmp, lhs_type, code, put_assign_to_memviewslice(lhs_cname, rhs, rhstmp, lhs_type, code,
have_gil=have_gil) have_gil=have_gil, first_assignment=first_assignment)
if not pretty_rhs: if not pretty_rhs:
code.funcstate.release_temp(rhstmp) code.funcstate.release_temp(rhstmp)
def put_assign_to_memviewslice(lhs_cname, rhs, rhs_cname, memviewslicetype, code, def put_assign_to_memviewslice(lhs_cname, rhs, rhs_cname, memviewslicetype, code,
have_gil=False): have_gil=False, first_assignment=False):
if not first_assignment:
code.put_xdecref_memoryviewslice(lhs_cname, have_gil=have_gil) code.put_xdecref_memoryviewslice(lhs_cname, have_gil=have_gil)
if rhs.is_name: if rhs.is_name:
code.put_incref_memoryviewslice(rhs_cname, have_gil=have_gil) code.put_incref_memoryviewslice(rhs_cname, have_gil=have_gil)
......
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