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:
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user