1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

minor perf changes

This commit is contained in:
Jan Pochyla 2016-12-12 15:20:20 +01:00
parent 53c73b3b5c
commit b8968e7387
2 changed files with 14 additions and 11 deletions

View File

@ -47,11 +47,10 @@ def unlock(user_pin: str, failure_callback=None) -> bool:
# lock, run the callback (ie for ui) and sleep for a quadratic delay
_locked = True
delay_ms = fails * fails * 1000
if failure_callback:
try:
if failure_callback:
failure_callback(delay_ms)
except:
pass
finally:
utime.sleep_ms(delay_ms)
return False
@ -158,6 +157,8 @@ def config_set_checked(key, value: bytes):
utils.halt('config.set failed')
# TODO: store ints as varints
def int_to_bytes(i: int) -> bytes:
return ustruct.pack('>L', i) if i else bytes()

View File

@ -14,9 +14,10 @@ def _unimport_func(func):
try:
ret = func(*args, **kwargs)
finally:
for to_remove in set(sys.modules) - mods:
log.debug(__name__, 'unimport %s', to_remove)
del sys.modules[to_remove]
for mod in sys.modules:
if mod not in mods:
log.debug(__name__, 'unimport %s', mod)
del sys.modules[mod]
gc.collect()
return ret
return inner
@ -28,9 +29,10 @@ def _unimport_genfunc(genfunc):
try:
ret = await genfunc(*args, **kwargs)
finally:
for to_remove in set(sys.modules) - mods:
log.debug(__name__, 'unimport %s', to_remove)
del sys.modules[to_remove]
for mod in sys.modules:
if mod not in mods:
log.debug(__name__, 'unimport %s', mod)
del sys.modules[mod]
gc.collect()
return ret
return inner