summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-09-02 15:10:45 +1000
committerDamien George <damien.p.george@gmail.com>2016-09-02 15:10:45 +1000
commitb6bdf18debfd75e9d39c2e8452c7b4ade448bcc5 (patch)
treee12051eab82d16a1f94a672b6f017a91c4e9636f
parentb4790afdafaf243ca7a1ec250917f30ed00a2d2d (diff)
downloadmicropython-b6bdf18debfd75e9d39c2e8452c7b4ade448bcc5.tar.gz
micropython-b6bdf18debfd75e9d39c2e8452c7b4ade448bcc5.zip
tools/mpy-tool.py: Compute the hash value for str/bytes objects.
This makes it more efficient at runtime to hash str/bytes objects.
-rwxr-xr-xtools/mpy-tool.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py
index c5bbf88e8b..bfb2a5da79 100755
--- a/tools/mpy-tool.py
+++ b/tools/mpy-tool.py
@@ -283,15 +283,15 @@ class RawCode:
# generate constant objects
for i, obj in enumerate(self.objs):
obj_name = 'const_obj_%s_%u' % (self.escaped_name, i)
- if is_str_type(obj):
- obj = bytes_cons(obj, 'utf8')
- print('STATIC const mp_obj_str_t %s = '
- '{{&mp_type_str}, 0, %u, (const byte*)"%s"};'
- % (obj_name, len(obj), ''.join(('\\x%02x' % b) for b in obj)))
- elif is_bytes_type(obj):
- print('STATIC const mp_obj_str_t %s = '
- '{{&mp_type_bytes}, 0, %u, (const byte*)"%s"};'
- % (obj_name, len(obj), ''.join(('\\x%02x' % b) for b in obj)))
+ if is_str_type(obj) or is_bytes_type(obj):
+ if is_str_type(obj):
+ obj = bytes_cons(obj, 'utf8')
+ obj_type = 'mp_type_str'
+ else:
+ obj_type = 'mp_type_bytes'
+ print('STATIC const mp_obj_str_t %s = {{&%s}, %u, %u, (const byte*)"%s"};'
+ % (obj_name, obj_type, qstrutil.compute_hash(obj, config.MICROPY_QSTR_BYTES_IN_HASH),
+ len(obj), ''.join(('\\x%02x' % b) for b in obj)))
elif is_int_type(obj):
if config.MICROPY_LONGINT_IMPL == config.MICROPY_LONGINT_IMPL_NONE:
# TODO check if we can actually fit this long-int into a small-int