Bug 1618620 - Convert gen_static_components.py to py3; r=firefox-build-system-reviewers,rstewart

Note that perfecthash.py is also used by other scripts, so it needs to
remain py2 compatible for now.

Differential Revision: https://phabricator.services.mozilla.com/D64620

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Shal 2020-02-28 21:27:17 +00:00
parent af329904b3
commit 449e9c0820
2 changed files with 10 additions and 3 deletions

View File

@ -41,7 +41,6 @@ if CONFIG['COMPILE_ENVIRONMENT']:
GeneratedFile(
'Components.h', 'StaticComponentData.h', 'StaticComponents.cpp',
script='gen_static_components.py',
py2=True,
inputs=['!manifest-lists.json', 'StaticComponents.cpp.in'])
UNIFIED_SOURCES += [

View File

@ -22,7 +22,9 @@ small dataset it was designed for. In the future we may want to optimize further
"""
from collections import namedtuple
from mozbuild.util import ensure_bytes
import textwrap
import six
class PerfectHash(object):
@ -114,13 +116,19 @@ class PerfectHash(object):
stored in that table is used as the offset basis for indexing into the
values table."""
for byte in memoryview(key):
basis ^= ord(byte) # xor-in the byte
# Python2 can't ^= the raw byte since it is a 'str', and Python3
# can't call ord(byte) because byte is an 'int'.
if six.PY3:
obyte = byte
else:
obyte = ord(byte)
basis ^= obyte # xor-in the byte
basis *= cls.FNV_PRIME # Multiply by the FNV prime
basis &= cls.U32_MAX # clamp to 32-bits
return basis
def key(self, entry):
return memoryview(self._key(entry))
return memoryview(ensure_bytes(self._key(entry)))
def get_raw_index(self, key):
"""Determine the index in self.entries without validating"""