Skip to content

Commit

Permalink
don't zero gcref arrays, the GC has to have done it
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbolz committed Jan 3, 2025
1 parent 7568bd9 commit e0f53e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions pypy/objspace/std/listobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,7 @@ def _list_resize_hint_really(self, w_list, newsize, overallocate):
else:
new_allocated = newsize
l = self.unerase(w_list.lstorage)
assert new_allocated >= 0
newitems = [self._none_value] * new_allocated
before_len = w_list.length()
if before_len:
Expand Down
18 changes: 10 additions & 8 deletions rpython/rtyper/rlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,10 @@ def _ll_zero_or_null(item):
return not check

@specialize.memo()
def _null_of_type(T):
return T._defl()
def _is_array_of_gcref(T):
ITEM = T.ITEM
return isinstance(ITEM, Ptr) and ITEM.TO._gckind == 'gc'


def ll_alloc_and_set(LIST, count, item):
count = int_force_ge_zero(count)
Expand Down Expand Up @@ -519,14 +521,14 @@ def _ll_alloc_and_set_jit(LIST, count, item):

@jit.oopspec("newlist_clear(count)")
def _ll_alloc_and_clear(LIST, count):
from rpython.rlib.rgc import ll_arrayclear
l = LIST.ll_newlist(count)
if malloc_zero_filled:
if malloc_zero_filled or _is_array_of_gcref(LIST):
# if it's an array of gcrefs, we don't need to clear it (the
# exceptiontransformer inserts clear calls, otherwise the GC would
# crash)
return l
zeroitem = _null_of_type(LIST.ITEM)
i = 0
while i < count:
l.ll_setitem_fast(i, zeroitem)
i += 1
ll_arrayclear(l.ll_items())
return l

@jit.look_inside_iff(lambda LIST, count, item: jit.isconstant(count) and count < 137)
Expand Down

0 comments on commit e0f53e6

Please sign in to comment.