Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
b6bdf18d
Commit
b6bdf18d
authored
Sep 02, 2016
by
Damien George
Browse files
tools/mpy-tool.py: Compute the hash value for str/bytes objects.
This makes it more efficient at runtime to hash str/bytes objects.
parent
b4790afd
Changes
1
Hide whitespace changes
Inline
Side-by-side
tools/mpy-tool.py
View file @
b6bdf18d
...
...
@@ -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
,
(
con
st 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
,
con
fig
.
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment