Example #1
0
def ll_call_lookup_function(d, key, hash, flag):
    fun = d.lookup_function_no & FUNC_MASK
    # This likely() here forces gcc to compile the check for fun == FUNC_BYTE
    # first.  Otherwise, this is a regular switch and gcc (at least 4.7)
    # compiles this as a series of checks, with the FUNC_BYTE case last.
    # It sounds minor, but it is worth 6-7% on a PyPy microbenchmark.
    if likely(fun == FUNC_BYTE):
        return ll_dict_lookup(d, key, hash, flag, TYPE_BYTE)
    elif fun == FUNC_SHORT:
        return ll_dict_lookup(d, key, hash, flag, TYPE_SHORT)
    elif IS_64BIT and fun == FUNC_INT:
        return ll_dict_lookup(d, key, hash, flag, TYPE_INT)
    elif fun == FUNC_LONG:
        return ll_dict_lookup(d, key, hash, flag, TYPE_LONG)
    assert False
Example #2
0
def ll_call_lookup_function(d, key, hash, flag):
    fun = d.lookup_function_no & FUNC_MASK
    # This likely() here forces gcc to compile the check for fun == FUNC_BYTE
    # first.  Otherwise, this is a regular switch and gcc (at least 4.7)
    # compiles this as a series of checks, with the FUNC_BYTE case last.
    # It sounds minor, but it is worth 6-7% on a PyPy microbenchmark.
    if likely(fun == FUNC_BYTE):
        return ll_dict_lookup(d, key, hash, flag, TYPE_BYTE)
    elif fun == FUNC_SHORT:
        return ll_dict_lookup(d, key, hash, flag, TYPE_SHORT)
    elif IS_64BIT and fun == FUNC_INT:
        return ll_dict_lookup(d, key, hash, flag, TYPE_INT)
    elif fun == FUNC_LONG:
        return ll_dict_lookup(d, key, hash, flag, TYPE_LONG)
    assert False
Example #3
0
 def f(n):
     if unlikely(n > 50):
         return -10
     if likely(n > 5):
         return 42
     return 3