def _ll_list_resize_le(l, newsize): """This is called with 'newsize' smaller than the current length of the list. If 'newsize' falls lower than half the allocated size, proceed with the realloc() to shrink the list. """ cond = newsize < (len(l.items) >> 1) - 5 if jit.isconstant(len(l.items)) and jit.isconstant(newsize): if cond: _ll_list_resize_hint_really(l, newsize, False) else: jit.conditional_call(cond, _ll_list_resize_hint_really, l, newsize, False) l.length = newsize
def _ll_list_resize_le(l, newsize): """This is called with 'newsize' smaller than the current length of the list. If 'newsize' falls lower than half the allocated size, proceed with the realloc() to shrink the list. """ cond = newsize < (len(l.items) >> 1) - 5 # note: overallocate=False should be safe here if jit.isconstant(len(l.items)) and jit.isconstant(newsize): if cond: _ll_list_resize_hint_really(l, newsize, False) else: jit.conditional_call(cond, _ll_list_resize_hint_really, l, newsize, False) l.length = newsize
def _ll_list_resize_ge(l, newsize): """This is called with 'newsize' larger than the current length of the list. If the list storage doesn't have enough space, then really perform a realloc(). In the common case where we already overallocated enough, then this is a very fast operation. """ cond = len(l.items) < newsize if jit.isconstant(len(l.items)) and jit.isconstant(newsize): if cond: _ll_list_resize_hint_really(l, newsize, True) else: jit.conditional_call(cond, _ll_list_resize_hint_really, l, newsize, True) l.length = newsize
def ll_prepare_dict_update(d, num_extra): # Prescale 'd' for 'num_extra' items, assuming that most items don't # collide. If this assumption is false, 'd' becomes too large by at # most 'num_extra'. The logic is based on: # (d.resize_counter - 1) // 3 = room left in d # so, if num_extra == 1, we need d.resize_counter > 3 # if num_extra == 2, we need d.resize_counter > 6 etc. # Note however a further hack: if num_extra <= d.num_live_items, # we avoid calling _ll_dict_resize_to here. This is to handle # the case where dict.update() actually has a lot of collisions. # If num_extra is much greater than d.num_live_items the conditional_call # will trigger anyway, which is really the goal. x = num_extra - d.num_live_items jit.conditional_call(d.resize_counter <= x * 3, _ll_dict_resize_to, d, num_extra)
def ll_prepare_dict_update(d, num_extra): # Prescale 'd' for 'num_extra' items, assuming that most items don't # collide. If this assumption is false, 'd' becomes too large by at # most 'num_extra'. The logic is based on: # (d.resize_counter - 1) // 3 = room left in d # so, if num_extra == 1, we need d.resize_counter > 3 # if num_extra == 2, we need d.resize_counter > 6 etc. # Note however a further hack: if num_extra <= d.num_items, # we avoid calling _ll_dict_resize_to here. This is to handle # the case where dict.update() actually has a lot of collisions. # If num_extra is much greater than d.num_items the conditional_call # will trigger anyway, which is really the goal. x = num_extra - d.num_items jit.conditional_call(d.resize_counter <= x * 3, _ll_dict_resize_to, d, num_extra)
def ll_append_char(ll_builder, char): jit.conditional_call(ll_builder.current_pos == ll_builder.current_end, ll_grow_by, ll_builder, 1) pos = ll_builder.current_pos ll_builder.current_pos = pos + 1 ll_builder.current_buf.chars[pos] = char
def _delete_from_start(self, n): assert n >= 0 self._offset += n jit.conditional_call(self._offset > len(self._data) / 2, _shrink_after_delete_from_start, self)
def later(m): conditional_call(m, g)
def f(n): conditional_call(n >= 0, g)
def main(n): while n > 0: driver.jit_merge_point(n=n) jit.conditional_call(False, f, 10) n -= 1 return 42
def main(n): l = [] jit.conditional_call(n == 10, f, l, n) return len(l)