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

View File

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