[Bf-blender-cvs] [4f0a749489a] master: Cleanup: use LISTBASE_FOREACH in writefile.c

Jacques Lucke noreply at git.blender.org
Fri Aug 21 13:14:49 CEST 2020


Commit: 4f0a749489af9de9b2ec0b5768d6e10898885a17
Author: Jacques Lucke
Date:   Fri Aug 21 13:14:41 2020 +0200
Branches: master
https://developer.blender.org/rB4f0a749489af9de9b2ec0b5768d6e10898885a17

Cleanup: use LISTBASE_FOREACH in writefile.c

===================================================================

M	source/blender/blenloader/intern/writefile.c

===================================================================

diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 74829c3ae32..698eefa4979 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -710,13 +710,11 @@ static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig)
 
 static void write_fmodifiers(BlendWriter *writer, ListBase *fmodifiers)
 {
-  FModifier *fcm;
-
   /* Write all modifiers first (for faster reloading) */
   BLO_write_struct_list(writer, FModifier, fmodifiers);
 
   /* Modifiers */
-  for (fcm = fmodifiers->first; fcm; fcm = fcm->next) {
+  LISTBASE_FOREACH (FModifier *, fcm, fmodifiers) {
     const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm);
 
     /* Write the specific data */
@@ -762,10 +760,8 @@ static void write_fmodifiers(BlendWriter *writer, ListBase *fmodifiers)
 
 static void write_fcurves(BlendWriter *writer, ListBase *fcurves)
 {
-  FCurve *fcu;
-
   BLO_write_struct_list(writer, FCurve, fcurves);
-  for (fcu = fcurves->first; fcu; fcu = fcu->next) {
+  LISTBASE_FOREACH (FCurve *, fcu, fcurves) {
     /* curve data */
     if (fcu->bezt) {
       BLO_write_struct_array(writer, BezTriple, fcu->totvert, fcu->bezt);
@@ -781,13 +777,12 @@ static void write_fcurves(BlendWriter *writer, ListBase *fcurves)
     /* driver data */
     if (fcu->driver) {
       ChannelDriver *driver = fcu->driver;
-      DriverVar *dvar;
 
       BLO_write_struct(writer, ChannelDriver, driver);
 
       /* variables */
       BLO_write_struct_list(writer, DriverVar, &driver->variables);
-      for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
+      LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
         DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
           if (dtar->rna_path) {
             BLO_write_string(writer, dtar->rna_path);
@@ -822,15 +817,12 @@ static void write_action(BlendWriter *writer, bAction *act, const void *id_addre
 
 static void write_keyingsets(BlendWriter *writer, ListBase *list)
 {
-  KeyingSet *ks;
-  KS_Path *ksp;
-
-  for (ks = list->first; ks; ks = ks->next) {
+  LISTBASE_FOREACH (KeyingSet *, ks, list) {
     /* KeyingSet */
     BLO_write_struct(writer, KeyingSet, ks);
 
     /* Paths */
-    for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
+    LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) {
       /* Path */
       BLO_write_struct(writer, KS_Path, ksp);
 
@@ -843,10 +835,8 @@ static void write_keyingsets(BlendWriter *writer, ListBase *list)
 
 static void write_nlastrips(BlendWriter *writer, ListBase *strips)
 {
-  NlaStrip *strip;
-
   BLO_write_struct_list(writer, NlaStrip, strips);
-  for (strip = strips->first; strip; strip = strip->next) {
+  LISTBASE_FOREACH (NlaStrip *, strip, strips) {
     /* write the strip's F-Curves and modifiers */
     write_fcurves(writer, &strip->fcurves);
     write_fmodifiers(writer, &strip->modifiers);
@@ -858,10 +848,8 @@ static void write_nlastrips(BlendWriter *writer, ListBase *strips)
 
 static void write_nladata(BlendWriter *writer, ListBase *nlabase)
 {
-  NlaTrack *nlt;
-
   /* write all the tracks */
-  for (nlt = nlabase->first; nlt; nlt = nlt->next) {
+  LISTBASE_FOREACH (NlaTrack *, nlt, nlabase) {
     /* write the track first */
     BLO_write_struct(writer, NlaTrack, nlt);
 
@@ -872,8 +860,6 @@ static void write_nladata(BlendWriter *writer, ListBase *nlabase)
 
 static void write_animdata(BlendWriter *writer, AnimData *adt)
 {
-  AnimOverride *aor;
-
   /* firstly, just write the AnimData block */
   BLO_write_struct(writer, AnimData, adt);
 
@@ -882,7 +868,7 @@ static void write_animdata(BlendWriter *writer, AnimData *adt)
 
   /* write overrides */
   // FIXME: are these needed?
-  for (aor = adt->overrides.first; aor; aor = aor->next) {
+  LISTBASE_FOREACH (AnimOverride *, aor, &adt->overrides) {
     /* overrides consist of base data + rna_path */
     BLO_write_struct(writer, AnimOverride, aor);
     BLO_write_string(writer, aor->rna_path);
@@ -962,31 +948,27 @@ static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock)
 /* this is only direct data, tree itself should have been written */
 static void write_nodetree_nolib(BlendWriter *writer, bNodeTree *ntree)
 {
-  bNode *node;
-  bNodeSocket *sock;
-  bNodeLink *link;
-
   /* for link_list() speed, we write per list */
 
   if (ntree->adt) {
     write_animdata(writer, ntree->adt);
   }
 
-  for (node = ntree->nodes.first; node; node = node->next) {
+  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
     BLO_write_struct(writer, bNode, node);
 
     if (node->prop) {
       IDP_BlendWrite(writer, node->prop);
     }
 
-    for (sock = node->inputs.first; sock; sock = sock->next) {
+    LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
       write_node_socket(writer, sock);
     }
-    for (sock = node->outputs.first; sock; sock = sock->next) {
+    LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
       write_node_socket(writer, sock);
     }
 
-    for (link = node->internal_links.first; link; link = link->next) {
+    LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) {
       BLO_write_struct(writer, bNodeLink, link);
     }
 
@@ -1050,26 +1032,26 @@ static void write_nodetree_nolib(BlendWriter *writer, bNodeTree *ntree)
 
     if (node->type == CMP_NODE_OUTPUT_FILE) {
       /* inputs have own storage data */
-      for (sock = node->inputs.first; sock; sock = sock->next) {
+      LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
         BLO_write_struct(writer, NodeImageMultiFileSocket, sock->storage);
       }
     }
     if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) {
       /* write extra socket info */
-      for (sock = node->outputs.first; sock; sock = sock->next) {
+      LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
         BLO_write_struct(writer, NodeImageLayer, sock->storage);
       }
     }
   }
 
-  for (link = ntree->links.first; link; link = link->next) {
+  LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
     BLO_write_struct(writer, bNodeLink, link);
   }
 
-  for (sock = ntree->inputs.first; sock; sock = sock->next) {
+  LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) {
     write_node_socket_interface(writer, sock);
   }
-  for (sock = ntree->outputs.first; sock; sock = sock->next) {
+  LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) {
     write_node_socket_interface(writer, sock);
   }
 }
@@ -1131,15 +1113,15 @@ typedef struct RenderInfo {
 static void write_renderinfo(WriteData *wd, Main *mainvar)
 {
   bScreen *curscreen;
-  Scene *sce, *curscene = NULL;
+  Scene *curscene = NULL;
   ViewLayer *view_layer;
-  RenderInfo data;
 
   /* XXX in future, handle multiple windows with multiple screens? */
   current_screen_compat(mainvar, false, &curscreen, &curscene, &view_layer);
 
-  for (sce = mainvar->scenes.first; sce; sce = sce->id.next) {
+  LISTBASE_FOREACH (Scene *, sce, &mainvar->scenes) {
     if (sce->id.lib == NULL && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) {
+      RenderInfo data;
       data.sfra = sce->r.sfra;
       data.efra = sce->r.efra;
       memset(data.scene_name, 0, sizeof(data.scene_name));
@@ -1234,11 +1216,9 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef)
 
 static void write_boid_state(BlendWriter *writer, BoidState *state)
 {
-  BoidRule *rule = state->rules.first;
-
   BLO_write_struct(writer, BoidState, state);
 
-  for (; rule; rule = rule->next) {
+  LISTBASE_FOREACH (BoidRule *, rule, &state->rules) {
     switch (rule->type) {
       case eBoidRuleType_Goal:
       case eBoidRuleType_Avoid:
@@ -1287,21 +1267,14 @@ static const char *ptcache_extra_struct[] = {
 };
 static void write_pointcaches(BlendWriter *writer, ListBase *ptcaches)
 {
-  PointCache *cache = ptcaches->first;
-  int i;
-
-  for (; cache; cache = cache->next) {
+  LISTBASE_FOREACH (PointCache *, cache, ptcaches) {
     BLO_write_struct(writer, PointCache, cache);
 
     if ((cache->flag & PTCACHE_DISK_CACHE) == 0) {
-      PTCacheMem *pm = cache->mem_cache.first;
-
-      for (; pm; pm = pm->next) {
-        PTCacheExtra *extra = pm->extradata.first;
-
+      LISTBASE_FOREACH (PTCacheMem *, pm, &cache->mem_cache) {
         BLO_write_struct(writer, PTCacheMem, pm);
 
-        for (i = 0; i < BPHYS_TOT_DATA; i++) {
+        for (int i = 0; i < BPHYS_TOT_DATA; i++) {
           if (pm->data[i] && pm->data_types & (1 << i)) {
             if (ptcache_data_struct[i][0] == '\0') {
               BLO_write_raw(writer, MEM_allocN_len(pm->data[i]), pm->data[i]);
@@ -1313,7 +1286,7 @@ static void write_pointcaches(BlendWriter *writer, ListBase *ptcaches)
           }
         }
 
-        for (; extra; extra = extra->next) {
+        LISTBASE_FOREACH (PTCacheExtra *, extra, &pm->extradata) {
           if (ptcache_extra_struct[extra->type][0] == '\0') {
             continue;
           }
@@ -1390,11 +1363,7 @@ static void write_particlesettings(BlendWriter *writer,
 
 static void write_particlesystems(BlendWriter *writer, ListBase *particles)
 {
-  ParticleSystem *psys = particles->first;
-  ParticleTarget *pt;
-  int a;
-
-  for (; psys; psys = psys->next) {
+  LISTBASE_FOREACH (ParticleSystem *, psys, particles) {
     BLO_write_struct(writer, ParticleSystem, psys);
 
     if (psys->particles) {
@@ -1403,7 +1372,7 @@ static void write_particlesystems(BlendWriter *writer, ListBase *particles)
       if (psys->particles->hair) {
         ParticleData *pa = psys->particles;
 
-        for (a = 0; a < psys->totpart; a++, pa++) {
+        for (int a = 0; a < psys->totpart; a++, pa++) {
           BLO_write_struct_array(writer, HairKey, pa->totkey, pa->hair);
         }
       }
@@ -1418,8 +1387,7 @@ static void write_particlesystems(BlendWriter *writer, ListBase *particles)
             writer, ParticleSpring, psys->tot_fluidsprings, psys->fluid_springs);
       }
     }
-    pt = psys->targets.first;
-    for (; pt; pt = pt->next) {
+    LISTBASE_FOREACH (ParticleTarget *, pt, &psys->targets) {
       BLO_write_struct(writer, ParticleTarget, pt);
     }
 
@@ -1453,9 +1421,7 @@ static void write_motionpath(BlendWriter *writer, bMotionPath *mpath

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list