state: don't keep the previous state components in xkb_state There is really no need to keep this in the struct, we can just allocate it on the stack when we need to. Don't know why I did it this way. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/src/state.c b/src/state.c
index 19b372a..1b18f21 100644
--- a/src/state.c
+++ b/src/state.c
@@ -89,10 +89,10 @@ struct state_components {
struct xkb_state {
/*
- * Before updating the state, we keep a copy. This allows us to report
- * which components of the state have changed.
+ * Before updating the state, we keep a copy of just this struct. This
+ * allows us to report which components of the state have changed.
*/
- struct state_components cur, prev;
+ struct state_components cur;
/*
* At each event, we accumulate all the needed modifications to the base
@@ -703,12 +703,13 @@ xkb_state_update_key(struct xkb_state *state, xkb_keycode_t kc,
{
xkb_mod_index_t i;
xkb_mod_mask_t bit;
+ struct state_components prev_components;
const struct xkb_key *key = XkbKey(state->keymap, kc);
if (!key)
return 0;
- state->prev = state->cur;
+ prev_components = state->cur;
state->set_mods = 0;
state->clear_mods = 0;
@@ -736,7 +737,7 @@ xkb_state_update_key(struct xkb_state *state, xkb_keycode_t kc,
xkb_state_update_derived(state);
- return get_state_component_changes(&state->prev, &state->cur);
+ return get_state_component_changes(&prev_components, &state->cur);
}
/**
@@ -755,10 +756,11 @@ xkb_state_update_mask(struct xkb_state *state,
xkb_layout_index_t latched_group,
xkb_layout_index_t locked_group)
{
+ struct state_components prev_components;
xkb_mod_index_t num_mods;
xkb_mod_index_t idx;
- state->prev = state->cur;
+ prev_components = state->cur;
state->cur.base_mods = 0;
state->cur.latched_mods = 0;
@@ -781,7 +783,7 @@ xkb_state_update_mask(struct xkb_state *state,
xkb_state_update_derived(state);
- return get_state_component_changes(&state->prev, &state->cur);
+ return get_state_component_changes(&prev_components, &state->cur);
}
/**