mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-21 21:38:00 +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
@@ -415,7 +415,19 @@ static WSavedState *getWindowState(WScreen * scr, WMPropList * win_state)
|
||||
return state;
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
void wSessionRestoreState(WScreen *scr)
|
||||
{
|
||||
@@ -503,8 +515,10 @@ void wSessionRestoreState(WScreen *scr)
|
||||
if (dock != NULL) {
|
||||
for (j = 0; j < dock->max_icons; j++) {
|
||||
btn = dock->icon_array[j];
|
||||
if (btn && SAME(instance, btn->wm_instance) &&
|
||||
SAME(class, btn->wm_class) && SAME(command, btn->command) && !btn->launching) {
|
||||
if (btn && is_same(instance, btn->wm_instance) &&
|
||||
is_same(class, btn->wm_class) &&
|
||||
is_same(command, btn->command) &&
|
||||
!btn->launching) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
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