mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-24 23:22:30 +01:00
wmaker: converted macro 'SAME' into a static function
There are some risks associated with the way arguments are used in macros, and using a function also allows check on the type of arguments and leaves more room to the compiler for making the best optimisation choice; it also allows writing easier to read code (and thus, to maintain). As a side effect, this should also help Coverity in avoiding false positive bug reports (like #109605 and #109607). Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
6ef343ed87
commit
c8ea949b1a
19
src/window.c
19
src/window.c
@@ -2621,7 +2621,19 @@ WMagicNumber wWindowAddSavedState(const char *instance, const char *class,
|
||||
return wstate;
|
||||
}
|
||||
|
||||
#define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
|
||||
static inline int is_same(const char *x, const char *y)
|
||||
{
|
||||
if ((x == NULL) && (y == NULL))
|
||||
return 1;
|
||||
|
||||
if ((x == NULL) || (y == NULL))
|
||||
return 0;
|
||||
|
||||
if (strcmp(x, y) == 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
WMagicNumber wWindowGetSavedState(Window win)
|
||||
{
|
||||
@@ -2637,8 +2649,9 @@ WMagicNumber wWindowGetSavedState(Window win)
|
||||
|
||||
if (PropGetWMClass(win, &class, &instance)) {
|
||||
while (wstate) {
|
||||
if (SAME(instance, wstate->instance) &&
|
||||
SAME(class, wstate->class) && SAME(command, wstate->command)) {
|
||||
if (is_same(instance, wstate->instance) &&
|
||||
is_same(class, wstate->class) &&
|
||||
is_same(command, wstate->command)) {
|
||||
break;
|
||||
}
|
||||
wstate = wstate->next;
|
||||
|
||||
Reference in New Issue
Block a user