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,4 +1,4 @@
from kmk.keys import make_argumented_key
from kmk.keys import KC, maybe_make_argumented_key
from kmk.modules import Module
@@ -12,11 +12,13 @@ class StickyMod(Module):
def __init__(self):
self._active = False
self._active_key = None
make_argumented_key(
names=('SM',),
validator=StickyModMeta,
on_press=self.sm_pressed,
on_release=self.sm_released,
KC._generators.append(
maybe_make_argumented_key(
names=('SM',),
validator=StickyModMeta,
on_press=self.sm_pressed,
on_release=self.sm_released,
)
)
def during_bootup(self, keyboard):