Commit 449e9c08 authored by Mike Shal's avatar Mike Shal
Browse files

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
parent af329904
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -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 += [
+10 −2
Original line number Diff line number Diff line
@@ -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"""