mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 09:45:18 +00:00
make Mnemonic.mnemonic_decode faster
list.index(word) is O(n) dict[word] is O(log(n)) This makes a difference for Mnemonic.make_seed which calls self.mnemonic_decode repeatedly.
This commit is contained in:
parent
c2c291dd3a
commit
b3f913340c
1 changed files with 2 additions and 1 deletions
|
@ -126,6 +126,7 @@ class Mnemonic(Logger):
|
|||
self.logger.info(f'language {lang}')
|
||||
filename = filenames.get(lang[0:2], 'english.txt')
|
||||
self.wordlist = load_wordlist(filename)
|
||||
self.wordlist_indexes = {w: i for i, w in enumerate(self.wordlist)}
|
||||
self.logger.info(f"wordlist has {len(self.wordlist)} words")
|
||||
|
||||
@classmethod
|
||||
|
@ -156,7 +157,7 @@ class Mnemonic(Logger):
|
|||
i = 0
|
||||
while words:
|
||||
w = words.pop()
|
||||
k = self.wordlist.index(w)
|
||||
k = self.wordlist_indexes[w]
|
||||
i = i*n + k
|
||||
return i
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue