Commit 1976baee authored by Damien George's avatar Damien George
Browse files

Retain file order of qstr definitions.

Want common qstrs to be first in the list so they have the lowest ids,
so that in the byte code they take up the least room.
parent 60aca481
import argparse
import re
from htmlentitydefs import codepoint2name
# codepoint2name is different in Python 2 to Python 3
import platform
if platform.python_version_tuple()[0] == '2':
from htmlentitydefs import codepoint2name
elif platform.python_version_tuple()[0] == '3':
from html.entities import codepoint2name
# this must match the equivalent function in qstr.c
def compute_hash(qstr):
......@@ -37,13 +43,13 @@ def do_work(infiles):
if ident in qstrs:
# add the qstr to the list
qstrs[ident] = qstr
# add the qstr to the list, with order number to retain original order in file
qstrs[ident] = (len(qstrs), ident, qstr)
# process the qstrs, printing out the generated C header file
print('// This file was automatically generated by')
for ident, qstr in qstrs.items():
for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]):
qhash = compute_hash(qstr)
qlen = len(qstr)
print('Q({}, (const byte*)"\\x{:02x}\\x{:02x}\\x{:02x}\\x{:02x}" "{}")'.format(ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen & 0xff, (qlen >> 8) & 0xff, qstr))
Supports Markdown
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