From 466e0b82189352ee931916b22494f638fabc9aa3 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 27 Feb 2025 23:53:42 +0100 Subject: KeyValue: Don't wrap keys into a macro when possible Many kind of KeyValues don't need to be wrapped into a Macro to show a specific symbol. This is especially useful as Macro keys are not affected by modifiers. The parser is changed to have a fast-path when a key value is not a macro. --- srcs/juloo.keyboard2/KeyValue.java | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyValue.java') diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index b2ef5db..7cad9eb 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -250,7 +250,26 @@ public final class KeyValue implements Comparable public KeyValue withFlags(int f) { - return new KeyValue(_payload, (_code & KIND_BITS), (_code & VALUE_BITS), f); + return new KeyValue(_payload, (_code & ~FLAGS_BITS) | (f & FLAGS_BITS)); + } + + public KeyValue withSymbol(String symbol) + { + switch (getKind()) + { + case Char: + case Keyevent: + case Event: + case Compose_pending: + case Hangul_initial: + case Hangul_medial: + case Modifier: + case Editing: + case Placeholder: + return new KeyValue(symbol, _code); + default: + return makeMacro(symbol, new KeyValue[]{ this }, 0); + } } @Override @@ -294,13 +313,17 @@ public final class KeyValue implements Comparable return "[KeyValue " + getKind().toString() + "+" + getFlags() + "+" + value + " \"" + getString() + "\"]"; } - /** [value] is an unsigned integer. */ - private KeyValue(Comparable p, int kind, int value, int flags) + private KeyValue(Comparable p, int code) { if (p == null) throw new NullPointerException("KeyValue payload cannot be null"); _payload = p; - _code = (kind & KIND_BITS) | (flags & FLAGS_BITS) | (value & VALUE_BITS); + _code = code; + } + + private KeyValue(Comparable p, int kind, int value, int flags) + { + this(p, (kind & KIND_BITS) | (flags & FLAGS_BITS) | (value & VALUE_BITS)); } public KeyValue(Comparable p, Kind k, int v, int f) -- cgit v1.2.3