From d138cbfb47e379edc1ee915a8c6ff65b01f000d6 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 3 Apr 2020 19:15:01 +0200 Subject: Code Quality: Replace for loops with LISTBASE_FOREACH Note this only changes cases where the variable was declared inside the for loop. To handle it outside as well is a different challenge. Differential Revision: https://developer.blender.org/D7320 --- source/blender/editors/gpencil/gpencil_data.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source/blender/editors/gpencil/gpencil_data.c') diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index 24c3e9a0635..1e49195140c 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -522,7 +522,7 @@ static bool gp_layer_duplicate_object_poll(bContext *C) } /* check there are more grease pencil objects */ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if ((base->object != ob) && (base->object->type == OB_GPENCIL)) { return true; } @@ -571,7 +571,7 @@ static int gp_layer_duplicate_object_exec(bContext *C, wmOperator *op) gpl_dst->opacity = gpl_src->opacity; /* Create all frames. */ - for (bGPDframe *gpf_src = gpl_src->frames.first; gpf_src; gpf_src = gpf_src->next) { + LISTBASE_FOREACH (bGPDframe *, gpf_src, &gpl_src->frames) { if ((mode == GP_LAYER_COPY_OBJECT_ACT_FRAME) && (gpf_src != gpl_src->actframe)) { continue; @@ -581,7 +581,7 @@ static int gp_layer_duplicate_object_exec(bContext *C, wmOperator *op) bGPDframe *gpf_dst = BKE_gpencil_frame_addnew(gpl_dst, gpf_src->framenum); /* Copy strokes. */ - for (bGPDstroke *gps_src = gpf_src->strokes.first; gps_src; gps_src = gps_src->next) { + LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) { /* Make copy of source stroke. */ bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true); @@ -1184,12 +1184,12 @@ static int gp_merge_layer_exec(bContext *C, wmOperator *op) /* Collect frames of gpl_current in hash table to avoid O(n^2) lookups */ GHash *gh_frames_cur = BLI_ghash_int_new_ex(__func__, 64); - for (bGPDframe *gpf = gpl_current->frames.first; gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl_current->frames) { BLI_ghash_insert(gh_frames_cur, POINTER_FROM_INT(gpf->framenum), gpf); } /* read all frames from next layer and add any missing in current layer */ - for (bGPDframe *gpf = gpl_next->frames.first; gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl_next->frames) { /* try to find frame in current layer */ bGPDframe *frame = BLI_ghash_lookup(gh_frames_cur, POINTER_FROM_INT(gpf->framenum)); if (!frame) { @@ -1439,7 +1439,7 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op) switch (direction) { /* Bring to Front */ case GP_STROKE_MOVE_TOP: - for (LinkData *link = selected.first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &selected) { gps = link->data; BLI_remlink(&gpf->strokes, gps); BLI_addtail(&gpf->strokes, gps); @@ -1454,7 +1454,7 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op) break; /* Send Backward */ case GP_STROKE_MOVE_DOWN: - for (LinkData *link = selected.first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &selected) { gps = link->data; BLI_listbase_link_move(&gpf->strokes, gps, -1); } @@ -2529,7 +2529,7 @@ static void joined_gpencil_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data) /* Fix driver targets */ if (fcu->driver) { /* Fix driver references to invalid ID's */ - for (DriverVar *dvar = fcu->driver->variables.first; dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &fcu->driver->variables) { /* Only change the used targets, since the others will need fixing manually anyway. */ DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { /* Change the ID's used. */ @@ -2620,7 +2620,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) bGPdata *gpd_src = ob_iter->data; /* Apply all GP modifiers before */ - for (GpencilModifierData *md = ob_iter->greasepencil_modifiers.first; md; md = md->next) { + LISTBASE_FOREACH (GpencilModifierData *, md, &ob_iter->greasepencil_modifiers) { const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type); if (mti->bakeModifier) { mti->bakeModifier(bmain, depsgraph, md, ob_iter); @@ -2629,7 +2629,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) /* copy vertex groups to the base one's */ int old_idx = 0; - for (bDeformGroup *dg = ob_iter->defbase.first; dg; dg = dg->next) { + LISTBASE_FOREACH (bDeformGroup *, dg, &ob_iter->defbase) { bDeformGroup *vgroup = MEM_dupallocN(dg); int idx = BLI_listbase_count(&ob_active->defbase); BKE_object_defgroup_unique_name(vgroup, ob_active); @@ -2681,7 +2681,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) mul_m3_v3(imat, offset_global); mul_v3_m3v3(offset_local, imat, offset_global); - for (bGPDlayer *gpl_src = gpd_src->layers.first; gpl_src; gpl_src = gpl_src->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl_src, &gpd_src->layers) { bGPDlayer *gpl_new = BKE_gpencil_layer_duplicate(gpl_src); float diff_mat[4][4]; float inverse_diff_mat[4][4]; @@ -2691,7 +2691,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) invert_m4_m4(inverse_diff_mat, diff_mat); Material *ma_src = NULL; - for (bGPDframe *gpf = gpl_new->frames.first; gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl_new->frames) { LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* Reassign material. Look old material and try to find in destination. */ -- cgit v1.2.3