compat: only compute 'bool report' once 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 31326b0..2b09954 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -301,13 +301,13 @@ FindMatchingInterp(CompatInfo *info, SymInterpInfo *new)
static bool
UseNewInterpField(enum si_field field, SymInterpInfo *old, SymInterpInfo *new,
- int verbosity, enum si_field *collide)
+ bool report, enum si_field *collide)
{
if (!(old->defined & field))
return true;
if (new->defined & field) {
- if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
+ if (report)
*collide |= field;
if (new->merge != MERGE_AUGMENT)
@@ -320,16 +320,17 @@ UseNewInterpField(enum si_field field, SymInterpInfo *old, SymInterpInfo *new,
static bool
AddInterp(CompatInfo *info, SymInterpInfo *new)
{
- enum si_field collide;
+ enum si_field collide = 0;
SymInterpInfo *old;
- int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
- collide = 0;
old = FindMatchingInterp(info, new);
- if (old != NULL) {
+ if (old) {
+ int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
+ bool report = ((old->file_id == new->file_id && verbosity > 0) ||
+ verbosity > 9);
+
if (new->merge == MERGE_REPLACE) {
- if ((old->file_id == new->file_id && verbosity > 0) ||
- verbosity > 9)
+ if (report)
log_warn(info->keymap->ctx,
"Multiple definitions for \"%s\"; "
"Earlier interpretation ignored\n",
@@ -338,23 +339,23 @@ AddInterp(CompatInfo *info, SymInterpInfo *new)
return true;
}
- if (UseNewInterpField(SI_FIELD_VIRTUAL_MOD, old, new, verbosity,
+ if (UseNewInterpField(SI_FIELD_VIRTUAL_MOD, old, new, report,
&collide)) {
old->interp.virtual_mod = new->interp.virtual_mod;
old->defined |= SI_FIELD_VIRTUAL_MOD;
}
- if (UseNewInterpField(SI_FIELD_ACTION, old, new, verbosity,
+ if (UseNewInterpField(SI_FIELD_ACTION, old, new, report,
&collide)) {
old->interp.act = new->interp.act;
old->defined |= SI_FIELD_ACTION;
}
- if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, verbosity,
+ if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, report,
&collide)) {
old->interp.flags &= ~XkbSI_AutoRepeat;
old->interp.flags |= (new->interp.flags & XkbSI_AutoRepeat);
old->defined |= SI_FIELD_AUTO_REPEAT;
}
- if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, verbosity,
+ if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, report,
&collide)) {
old->interp.match &= ~XkbSI_LevelOneOnly;
old->interp.match |= (new->interp.match & XkbSI_LevelOneOnly);
@@ -427,13 +428,13 @@ ResolveStateAndPredicate(ExprDef *expr, unsigned *pred_rtrn,
static bool
UseNewLEDField(enum led_field field, LEDInfo *old, LEDInfo *new,
- int verbosity, enum led_field *collide)
+ bool report, enum led_field *collide)
{
if (!(old->defined & field))
return true;
if (new->defined & field) {
- if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
+ if (report)
*collide |= field;
if (new->merge != MERGE_AUGMENT)
@@ -452,6 +453,8 @@ AddIndicatorMap(CompatInfo *info, LEDInfo *new)
int verbosity = xkb_get_log_verbosity(ctx);
darray_foreach(old, info->leds) {
+ bool report;
+
if (old->name != new->name)
continue;
@@ -464,9 +467,11 @@ AddIndicatorMap(CompatInfo *info, LEDInfo *new)
return true;
}
+ report = ((old->file_id == new->file_id && verbosity > 0) ||
+ verbosity > 9);
+
if (new->merge == MERGE_REPLACE) {
- if ((old->file_id == new->file_id && verbosity > 0) ||
- verbosity > 9)
+ if (report)
log_warn(info->keymap->ctx,
"Map for indicator %s redefined; "
"Earlier definition ignored\n",
@@ -476,20 +481,17 @@ AddIndicatorMap(CompatInfo *info, LEDInfo *new)
}
collide = 0;
- if (UseNewLEDField(LED_FIELD_MODS, old, new, verbosity,
- &collide)) {
+ if (UseNewLEDField(LED_FIELD_MODS, old, new, report, &collide)) {
old->which_mods = new->which_mods;
old->mods = new->mods;
old->defined |= LED_FIELD_MODS;
}
- if (UseNewLEDField(LED_FIELD_GROUPS, old, new, verbosity,
- &collide)) {
+ if (UseNewLEDField(LED_FIELD_GROUPS, old, new, report, &collide)) {
old->which_groups = new->which_groups;
old->groups = new->groups;
old->defined |= LED_FIELD_GROUPS;
}
- if (UseNewLEDField(LED_FIELD_CTRLS, old, new, verbosity,
- &collide)) {
+ if (UseNewLEDField(LED_FIELD_CTRLS, old, new, report, &collide)) {
old->ctrls = new->ctrls;
old->defined |= LED_FIELD_CTRLS;
}