[Bf-blender-cvs] [f425f40c4e1] master: Cleanup: More miscellaneous code quality changes in wm directory
Hans Goudey
noreply at git.blender.org
Sat Oct 17 23:36:43 CEST 2020
Commit: f425f40c4e17e889c720647b26c07ae3f6d3ba64
Author: Hans Goudey
Date: Sat Oct 17 16:36:02 2020 -0500
Branches: master
https://developer.blender.org/rBf425f40c4e17e889c720647b26c07ae3f6d3ba64
Cleanup: More miscellaneous code quality changes in wm directory
- Declare variables where initialized.
- Use LISTBASE_FOREACH macro.
- Reduce variable scope.
- Return early or reduce indentation in some cases.
===================================================================
M source/blender/windowmanager/intern/wm.c
M source/blender/windowmanager/intern/wm_cursors.c
M source/blender/windowmanager/intern/wm_init_exit.c
M source/blender/windowmanager/intern/wm_jobs.c
M source/blender/windowmanager/intern/wm_keymap.c
M source/blender/windowmanager/intern/wm_menu_type.c
M source/blender/windowmanager/intern/wm_playanim.c
M source/blender/windowmanager/intern/wm_splash_screen.c
M source/blender/windowmanager/intern/wm_stereo.c
M source/blender/windowmanager/intern/wm_uilist_type.c
M source/blender/windowmanager/intern/wm_window.c
===================================================================
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index f25044b5df7..e7010461c68 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -188,7 +188,6 @@ void WM_operator_type_set(wmOperator *op, wmOperatorType *ot)
/* Ensure compatible properties. */
if (op->properties) {
PointerRNA ptr;
-
WM_operator_properties_create_ptr(&ptr, ot);
WM_operator_properties_default(&ptr, false);
@@ -251,8 +250,7 @@ void WM_operator_stack_clear(wmWindowManager *wm)
*/
void WM_operator_handlers_clear(wmWindowManager *wm, wmOperatorType *ot)
{
- wmWindow *win;
- for (win = wm->windows.first; win; win = win->next) {
+ LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
ListBase *lb[2] = {&win->handlers, &win->modalhandlers};
for (int i = 0; i < ARRAY_SIZE(lb); i++) {
LISTBASE_FOREACH (wmEventHandler *, handler_base, lb[i]) {
@@ -360,7 +358,6 @@ void WM_check(bContext *C)
void wm_clear_default_size(bContext *C)
{
wmWindowManager *wm = CTX_wm_manager(C);
- wmWindow *win;
/* WM context. */
if (wm == NULL) {
@@ -372,7 +369,7 @@ void wm_clear_default_size(bContext *C)
return;
}
- for (win = wm->windows.first; win; win = win->next) {
+ LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
win->sizex = 0;
win->sizey = 0;
win->posx = 0;
@@ -405,10 +402,6 @@ void wm_add_default(Main *bmain, bContext *C)
/* Context is allowed to be NULL, do not free wm itself (lib_id.c). */
void wm_close_and_free(bContext *C, wmWindowManager *wm)
{
- wmWindow *win;
- wmOperator *op;
- wmKeyConfig *keyconf;
-
if (wm->autosavetimer) {
wm_autosave_timer_ended(wm);
}
@@ -418,16 +411,19 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
wm_xr_exit(wm);
#endif
+ wmWindow *win;
while ((win = BLI_pophead(&wm->windows))) {
/* Prevent draw clear to use screen. */
BKE_workspace_active_set(win->workspace_hook, NULL);
wm_window_free(C, wm, win);
}
+ wmOperator *op;
while ((op = BLI_pophead(&wm->operators))) {
WM_operator_free(op);
}
+ wmKeyConfig *keyconf;
while ((keyconf = BLI_pophead(&wm->keyconfigs))) {
WM_keyconfig_free(keyconf);
}
@@ -457,7 +453,6 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
void wm_close_and_free_all(bContext *C, ListBase *wmlist)
{
wmWindowManager *wm;
-
while ((wm = wmlist->first)) {
wm_close_and_free(C, wm);
BLI_remlink(wmlist, wm);
diff --git a/source/blender/windowmanager/intern/wm_cursors.c b/source/blender/windowmanager/intern/wm_cursors.c
index b3185f57577..0f39e6ccf80 100644
--- a/source/blender/windowmanager/intern/wm_cursors.c
+++ b/source/blender/windowmanager/intern/wm_cursors.c
@@ -353,7 +353,6 @@ void WM_cursor_time(wmWindow *win, int nr)
};
uchar mask[16][2];
uchar bitmap[16][2] = {{0}};
- int i, idx;
if (win->lastcursor == 0) {
win->lastcursor = win->cursor;
@@ -362,12 +361,12 @@ void WM_cursor_time(wmWindow *win, int nr)
memset(&mask, 0xFF, sizeof(mask));
/* print number bottom right justified */
- for (idx = 3; nr && idx >= 0; idx--) {
+ for (int idx = 3; nr && idx >= 0; idx--) {
const char *digit = number_bitmaps[nr % 10];
int x = idx % 2;
int y = idx / 2;
- for (i = 0; i < 8; i++) {
+ for (int i = 0; i < 8; i++) {
bitmap[i + y * 8][x] = digit[i];
}
nr /= 10;
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index de47234695e..ac9d3848f3a 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -203,7 +203,7 @@ static void sound_jack_sync_callback(Main *bmain, int mode, double time)
wmWindowManager *wm = bmain->wm.first;
- for (wmWindow *window = wm->windows.first; window != NULL; window = window->next) {
+ LISTBASE_FOREACH (wmWindow *, window, &wm->windows) {
Scene *scene = WM_window_get_active_scene(window);
if ((scene->audio.flag & AUDIO_SYNC) == 0) {
continue;
@@ -479,8 +479,6 @@ void WM_exit_ex(bContext *C, const bool do_python)
/* modal handlers are on window level freed, others too? */
/* note; same code copied in wm_files.c */
if (C && wm) {
- wmWindow *win;
-
if (!G.background) {
struct MemFile *undo_memfile = wm->undo_stack ?
ED_undosys_stack_memfile_get_active(wm->undo_stack) :
@@ -507,8 +505,7 @@ void WM_exit_ex(bContext *C, const bool do_python)
WM_jobs_kill_all(wm);
- for (win = wm->windows.first; win; win = win->next) {
-
+ LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
CTX_wm_window_set(C, win); /* needed by operator close callbacks */
WM_event_remove_handlers(C, &win->handlers);
WM_event_remove_handlers(C, &win->modalhandlers);
diff --git a/source/blender/windowmanager/intern/wm_jobs.c b/source/blender/windowmanager/intern/wm_jobs.c
index 189657f7aa3..361b3ed3d7f 100644
--- a/source/blender/windowmanager/intern/wm_jobs.c
+++ b/source/blender/windowmanager/intern/wm_jobs.c
@@ -159,24 +159,22 @@ static void wm_job_main_thread_yield(wmJob *wm_job)
*/
static wmJob *wm_job_find(wmWindowManager *wm, void *owner, const int job_type)
{
- wmJob *wm_job;
-
if (owner && job_type) {
- for (wm_job = wm->jobs.first; wm_job; wm_job = wm_job->next) {
+ LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) {
if (wm_job->owner == owner && wm_job->job_type == job_type) {
return wm_job;
}
}
}
else if (owner) {
- for (wm_job = wm->jobs.first; wm_job; wm_job = wm_job->next) {
+ LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) {
if (wm_job->owner == owner) {
return wm_job;
}
}
}
else if (job_type) {
- for (wm_job = wm->jobs.first; wm_job; wm_job = wm_job->next) {
+ LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) {
if (wm_job->job_type == job_type) {
return wm_job;
}
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 3d9ca281897..3b792744d40 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -147,17 +147,12 @@ static void wm_keymap_item_properties_update_ot(wmKeyMapItem *kmi)
static void wm_keymap_item_properties_update_ot_from_list(ListBase *km_lb)
{
- wmKeyMap *km;
- wmKeyMapItem *kmi;
-
- for (km = km_lb->first; km; km = km->next) {
- wmKeyMapDiffItem *kmdi;
-
- for (kmi = km->items.first; kmi; kmi = kmi->next) {
+ LISTBASE_FOREACH (wmKeyMap *, km, km_lb) {
+ LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
wm_keymap_item_properties_update_ot(kmi);
}
- for (kmdi = km->diff_items.first; kmdi; kmdi = kmdi->next) {
+ LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &km->diff_items) {
if (kmdi->add_item) {
wm_keymap_item_properties_update_ot(kmdi->add_item);
}
diff --git a/source/blender/windowmanager/intern/wm_menu_type.c b/source/blender/windowmanager/intern/wm_menu_type.c
index dc4efe79433..0c52e636e4d 100644
--- a/source/blender/windowmanager/intern/wm_menu_type.c
+++ b/source/blender/windowmanager/intern/wm_menu_type.c
@@ -41,10 +41,8 @@ static GHash *menutypes_hash = NULL;
MenuType *WM_menutype_find(const char *idname, bool quiet)
{
- MenuType *mt;
-
if (idname[0]) {
- mt = BLI_ghash_lookup(menutypes_hash, idname);
+ MenuType *mt = BLI_ghash_lookup(menutypes_hash, idname);
if (mt) {
return mt;
}
@@ -71,12 +69,10 @@ bool WM_menutype_add(MenuType *mt)
void WM_menutype_freelink(MenuType *mt)
{
- bool ok;
-
- ok = BLI_ghash_remove(menutypes_hash, mt->idname, NULL, MEM_freeN);
+ bool ok = BLI_ghash_remove(menutypes_hash, mt->idname, NULL, MEM_freeN);
BLI_assert(ok);
- (void)ok;
+ UNUSED_VARS_NDEBUG(ok);
}
/* called on initialize WM_init() */
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index e3c763930c0..5d1607fe506 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -270,9 +270,8 @@ static PlayAnimPict *playanim_step(PlayAnimPict *playanim, int step)
static int pupdate_time(void)
{
static double ltime;
- double time;
- time = PIL_check_seconds_timer();
+ double time = PIL_check_seconds_timer();
ptottime += (time - ltime);
ltime = time;
@@ -282,9 +281,6 @@ static int pupdate_time(void)
static void playanim_toscreen(
PlayState *ps, PlayAnimPict *picture, struct ImBuf *ibuf, int fontid, int fstep)
{
- float offs_x, offs_y;
- float span_x, span_y;
-
if (ibuf == NULL) {
printf("%s: no ibuf for picture '%s'\n", __func__, picture ? picture->name : "<NIL>");
return;
@@ -300,12 +296,12 @@ static void playanim_toscreen(
GHOST_ActivateWindowDrawingContext(g_WS.ghost_window);
/* size within window */
- span_x = (ps->zoom * ibuf->x) / (float)ps->win_x;
- span_y = (ps->zoom * ibuf->y) / (float)ps->win_y;
+ float span_x = (ps->zoom * ibuf->x) / (float)ps->win_x;
+ float span_y = (ps->zoom * ibuf->y) / (float)ps->win_y;
/* offset within window */
- offs_x = 0.5f * (1.0f - span_x);
- offs_y = 0.5f * (1.0f - span_y);
+ float offs_x = 0.5f * (1.0f - span_x);
+ float offs_y = 0.5f * (1.0f - span_y);
CLAMP(offs_x, 0.0f, 1.0f);
CLAMP(offs_y, 0.0f, 1.0f);
@@ -392,26 +388,19 @@ static void playanim_toscreen(
static void build_pict_list_ex(
PlayState *ps, const char *first, int totframes, int fstep, int fontid)
{
- char filepath[FILE_MAX];
- uchar *mem;
- // short val;
- PlayAnimPict *picture = NULL;
- struct ImBuf *ibuf = NULL;
- struct anim *anim;
-
if (IMB_isanim(first)) {
/* OCIO_TODO: support different input color space */
- anim = IMB_open_anim(first, IB_rect, 0, NULL);
+ struct anim *anim = IMB_open_anim(first, IB_rect, 0, NULL);
if (anim) {
int pic;
- ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
+ struct ImBuf *ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list