Reduce key dictionary memory footprint

Instead of indexing `Key` objects that have multiple names by each
individual name, index by the set of names. This reduces the size of the
default key dictionary by a factor of between 2 and 3, and as result
also reduces reallocations/defragmentation.
Instead of instantiating all module/extension keys by default, append
them to the `maybe_key`-generator list.
This commit is contained in:
xs5871
2022-12-05 19:54:57 +00:00
parent 47c242a2c9
commit 9c1bd210eb
27 changed files with 439 additions and 434 deletions

View File

@@ -1,6 +1,6 @@
from micropython import const
from kmk.keys import KC, make_argumented_key
from kmk.keys import KC, maybe_make_argumented_key
from kmk.modules import Module
from kmk.utils import Debug
@@ -55,11 +55,13 @@ class HoldTap(Module):
self.key_buffer = []
self.key_states = {}
if not KC.get('HT'):
make_argumented_key(
validator=HoldTapKeyMeta,
names=('HT',),
on_press=self.ht_pressed,
on_release=self.ht_released,
KC._generators.append(
maybe_make_argumented_key(
validator=HoldTapKeyMeta,
names=('HT',),
on_press=self.ht_pressed,
on_release=self.ht_released,
)
)
def during_bootup(self, keyboard):