Exemplo n.º 1
0
 def ll_strhash(s):
     # unlike CPython, there is no reason to avoid to return -1
     # but our malloc initializes the memory to zero, so we use zero as the
     # special non-computed-yet value.
     x = s.hash
     if x == 0:
         x = _hash_string(s.chars)
         s.hash = x
     return x
Exemplo n.º 2
0
def hash__String(space, w_str):
    s = w_str._value
    if we_are_translated():
        x = hash(s)            # to use the hash cache in rpython strings
    else:
        x = _hash_string(s)    # to make sure we get the same hash as rpython
        # (otherwise translation will freeze W_DictObjects where we can't find
        #  the keys any more!)
    return wrapint(space, x)
Exemplo n.º 3
0
 def ll_strhash(s):
     # unlike CPython, there is no reason to avoid to return -1
     # but our malloc initializes the memory to zero, so we use zero as the
     # special non-computed-yet value.
     x = s.hash
     if x == 0:
         x = _hash_string(s.chars)
         s.hash = x
     return x
Exemplo n.º 4
0
def hash__String(space, w_str):
    s = w_str._value
    if we_are_translated():
        x = hash(s)  # to use the hash cache in rpython strings
    else:
        x = _hash_string(s)  # to make sure we get the same hash as rpython
        # (otherwise translation will freeze W_DictObjects where we can't find
        #  the keys any more!)
    return wrapint(space, x)
Exemplo n.º 5
0
def hash__Unicode(space, w_uni):
    s = w_uni._value
    if space.config.objspace.std.withrope:
        # be compatible with the special ropes hash
        # XXX no caching
        if len(s) == 0:
            return space.wrap(0)
        x = 0
        for c in s:
            x = intmask((1000003 * x) + ord(c))
        x <<= 1
        x ^= len(s)
        x ^= ord(s[0])
        h = intmask(x)
        return space.wrap(h)
    if we_are_translated():
        x = hash(s)  # to use the hash cache in rpython strings
    else:
        from pypy.rlib.rarithmetic import _hash_string
        x = _hash_string(s)  # to make sure we get the same hash as rpython
        # (otherwise translation will freeze W_DictObjects where we can't find
        #  the keys any more!)
    return space.wrap(x)
Exemplo n.º 6
0
def hash__Unicode(space, w_uni):
    s = w_uni._value
    if space.config.objspace.std.withrope:
        # be compatible with the special ropes hash
        # XXX no caching
        if len(s) == 0:
            return space.wrap(0)
        x = 0
        for c in s:
            x = intmask((1000003 * x) + ord(c))
        x <<= 1
        x ^= len(s)
        x ^= ord(s[0])
        h = intmask(x)
        return space.wrap(h)
    if we_are_translated():
        x = hash(s)            # to use the hash cache in rpython strings
    else:
        from pypy.rlib.rarithmetic import _hash_string
        x = _hash_string(s)    # to make sure we get the same hash as rpython
        # (otherwise translation will freeze W_DictObjects where we can't find
        #  the keys any more!)
    return space.wrap(x)