mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-24 19:51:28 +02:00
Refactor: Remove the KeyModifier cache
This commit is contained in:
parent
91ace060bc
commit
8d793da6b6
@ -6,19 +6,11 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public final class KeyModifier
|
public final class KeyModifier
|
||||||
{
|
{
|
||||||
/** Cache key is KeyValue's name */
|
|
||||||
private static HashMap<KeyValue, HashMap<Pointers.Modifiers, KeyValue>> _cache =
|
|
||||||
new HashMap<KeyValue, HashMap<Pointers.Modifiers, KeyValue>>();
|
|
||||||
|
|
||||||
/** The optional modmap takes priority over modifiers usual behaviors. Set to
|
/** The optional modmap takes priority over modifiers usual behaviors. Set to
|
||||||
[null] to disable. */
|
[null] to disable. */
|
||||||
private static KeyboardData.Modmap _modmap = null;
|
private static KeyboardData.Modmap _modmap = null;
|
||||||
public static void set_modmap(KeyboardData.Modmap mm)
|
public static void set_modmap(KeyboardData.Modmap mm)
|
||||||
{
|
{
|
||||||
// Clear the cache when switching to or from a layout that contain a modmap
|
|
||||||
// as the cache would otherwise override the modmap.
|
|
||||||
if (_modmap != null || mm != null)
|
|
||||||
_cache.clear();
|
|
||||||
_modmap = mm;
|
_modmap = mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,15 +20,9 @@ public final class KeyModifier
|
|||||||
if (k == null)
|
if (k == null)
|
||||||
return null;
|
return null;
|
||||||
int n_mods = mods.size();
|
int n_mods = mods.size();
|
||||||
HashMap<Pointers.Modifiers, KeyValue> ks = cacheEntry(k);
|
KeyValue r = k;
|
||||||
KeyValue r = ks.get(mods);
|
for (int i = 0; i < n_mods; i++)
|
||||||
if (r == null)
|
r = modify(r, mods.get(i));
|
||||||
{
|
|
||||||
r = k;
|
|
||||||
for (int i = 0; i < n_mods; i++)
|
|
||||||
r = modify(r, mods.get(i));
|
|
||||||
ks.put(mods, r);
|
|
||||||
}
|
|
||||||
/* Keys with an empty string are placeholder keys. */
|
/* Keys with an empty string are placeholder keys. */
|
||||||
if (r.getString().length() == 0)
|
if (r.getString().length() == 0)
|
||||||
return null;
|
return null;
|
||||||
@ -529,18 +515,6 @@ public final class KeyModifier
|
|||||||
return shifted;
|
return shifted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lookup the cache entry for a key. Create it needed. */
|
|
||||||
private static HashMap<Pointers.Modifiers, KeyValue> cacheEntry(KeyValue k)
|
|
||||||
{
|
|
||||||
HashMap<Pointers.Modifiers, KeyValue> ks = _cache.get(k);
|
|
||||||
if (ks == null)
|
|
||||||
{
|
|
||||||
ks = new HashMap<Pointers.Modifiers, KeyValue>();
|
|
||||||
_cache.put(k, ks);
|
|
||||||
}
|
|
||||||
return ks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static abstract class Map_char
|
public static abstract class Map_char
|
||||||
{
|
{
|
||||||
/** Modify a char or return [null] if the modifier do not apply. Return a
|
/** Modify a char or return [null] if the modifier do not apply. Return a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user