Commit 073c54bd authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

hasher: Alias long for Python 3 compatibility

The L suffix was removed in Python 3. Fortunately this can be simply removed.
The long type was also removed in Python 3, where int does the same thing. Simply alias long to int on Python 3.
Works on both now Python 2 and 3 now, producing the same results as before.

Traceback (most recent call last):
  File "../../third_party/blink/renderer/build/scripts/make_names.py", line 33, in <module>
    import hasher
  File "C:\Google\chromium\src\third_party\blink\renderer\build\scripts\hasher.py", line 26
    return uint32_t(long.__rshift__(self, other) & ((1L << 32) - 1))
                                                      ^
SyntaxError: invalid syntax

Bug: 941669
Change-Id: Ib0369ebce8c3bd843ebbbe24188fbe941fa1a2ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2093471
Auto-Submit: Raul Tambre <raul@tambre.ee>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748072}
parent 4635dd1d
...@@ -20,19 +20,24 @@ ...@@ -20,19 +20,24 @@
# We've modified Victor's version to output hash values that match WTFString, # We've modified Victor's version to output hash values that match WTFString,
# which involves using a specific seed and some different constants. # which involves using a specific seed and some different constants.
import sys
if sys.version_info.major != 2:
long = int
class uint32_t(long): class uint32_t(long):
def __rshift__(self, other): def __rshift__(self, other):
return uint32_t(long.__rshift__(self, other) & ((1L << 32) - 1)) return uint32_t(long.__rshift__(self, other) & ((1 << 32) - 1))
def __lshift__(self, other): def __lshift__(self, other):
return uint32_t(long.__lshift__(self, other) & ((1L << 32) - 1)) return uint32_t(long.__lshift__(self, other) & ((1 << 32) - 1))
def __add__(self, other): def __add__(self, other):
return uint32_t(long.__add__(self, other) & ((1L << 32) - 1)) return uint32_t(long.__add__(self, other) & ((1 << 32) - 1))
def __xor__(self, other): def __xor__(self, other):
return uint32_t(long.__xor__(self, other) & ((1L << 32) - 1)) return uint32_t(long.__xor__(self, other) & ((1 << 32) - 1))
def hash(string): def hash(string):
...@@ -47,7 +52,7 @@ def hash(string): ...@@ -47,7 +52,7 @@ def hash(string):
if not string: if not string:
return 0 return 0
result = uint32_t(0x9E3779B9L) result = uint32_t(0x9E3779B9)
length = len(string) length = len(string)
remainder = length & 1 remainder = length & 1
length >>= 1 length >>= 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment