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,3 +1,4 @@
from kmk.handlers.stock import passthrough as handler_passthrough
from kmk.keys import KC, ModifierKey, make_key
from kmk.modules import Module
@@ -12,16 +13,26 @@ class CgSwap(Module):
KC.LGUI: KC.LCTL,
KC.RGUI: KC.RCTL,
}
make_key(
names=('CG_SWAP',),
)
make_key(
names=('CG_NORM',),
)
make_key(
names=('CG_TOGG',),
KC._generators.append(self.maybe_make_cgswap_key())
def maybe_make_cgswap_key(self):
keys = (
(('CG_SWAP',),),
(('CG_NORM',),),
(('CG_TOGG',),),
)
def closure(candidate):
for names in keys:
if candidate in names:
return make_key(
names=names,
on_press=handler_passthrough,
on_release=handler_passthrough,
)
return closure
def during_bootup(self, keyboard):
return