예제 #1
0
파일: rlist.py 프로젝트: charred/pypy
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
예제 #2
0
파일: rlist.py 프로젝트: zielmicha/pypy
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
예제 #3
0
파일: rlist.py 프로젝트: zielmicha/pypy
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
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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
예제 #7
0
 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)
예제 #8
0
파일: test_jit.py 프로젝트: zielmicha/pypy
 def later(m):
     conditional_call(m, g)
예제 #9
0
파일: test_jit.py 프로젝트: zielmicha/pypy
 def f(n):
     conditional_call(n >= 0, g)
예제 #10
0
파일: rbuilder.py 프로젝트: zielmicha/pypy
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
예제 #11
0
파일: test_jit.py 프로젝트: mozillazg/pypy
 def later(m):
     conditional_call(m, g)
예제 #12
0
파일: test_jit.py 프로젝트: mozillazg/pypy
 def f(n):
     conditional_call(n >= 0, g)
예제 #13
0
파일: test_call.py 프로젝트: zielmicha/pypy
 def main(n):
     while n > 0:
         driver.jit_merge_point(n=n)
         jit.conditional_call(False, f, 10)
         n -= 1
     return 42
예제 #14
0
파일: test_call.py 프로젝트: zielmicha/pypy
 def main(n):
     l = []
     jit.conditional_call(n == 10, f, l, n)
     return len(l)
예제 #15
0
 def main(n):
     while n > 0:
         driver.jit_merge_point(n=n)
         jit.conditional_call(False, f, 10)
         n -= 1
     return 42
예제 #16
0
 def main(n):
     l = []
     jit.conditional_call(n == 10, f, l, n)
     return len(l)