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,5 @@
from kmk.keys import FIRST_KMK_INTERNAL_KEY, KC, ModifierKey, make_key
from kmk.handlers.stock import passthrough as handler_passthrough
from kmk.keys import FIRST_KMK_INTERNAL_KEY, KC, ModifierKey, maybe_make_key
from kmk.modules import Module
@@ -16,12 +17,16 @@ class CapsWord(Module):
self._timeout_key = False
self._cw_active = False
self.timeout = timeout
make_key(
KC._generators.append(self.maybe_make_capsword_key())
def maybe_make_capsword_key(self):
return maybe_make_key(
names=(
'CAPSWORD',
'CW',
),
on_press=self.cw_pressed,
on_release=handler_passthrough,
)
def during_bootup(self, keyboard):