[Bf-blender-cvs] [74c34c065cc] master: Cleanup: move region manipulation to utility functions

Brecht Van Lommel noreply at git.blender.org
Thu Apr 18 06:54:13 CEST 2019


Commit: 74c34c065cc4169dc2a00d246caaf81b15ad9336
Author: Brecht Van Lommel
Date:   Thu Apr 18 06:48:34 2019 +0200
Branches: master
https://developer.blender.org/rB74c34c065cc4169dc2a00d246caaf81b15ad9336

Cleanup: move region manipulation to utility functions

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

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

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

diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 0582bf05c25..d87b00876d0 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -580,6 +580,35 @@ static void do_versions_fix_annotations(bGPdata *gpd)
   }
 }
 
+static void do_versions_remove_region(ListBase *regionbase, int regiontype)
+{
+  ARegion *ar, *ar_next;
+  for (ar = regionbase->first; ar; ar = ar_next) {
+    ar_next = ar->next;
+    if (ar->regiontype == regiontype) {
+      BLI_freelinkN(regionbase, ar);
+    }
+  }
+}
+
+static ARegion *do_versions_find_region(ListBase *regionbase, int regiontype)
+{
+  for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
+    if (ar->regiontype == regiontype) {
+      return ar;
+    }
+  }
+  BLI_assert(!"Did not find expected region in versioning");
+  return NULL;
+}
+
+static ARegion *do_versions_add_region(int regiontype, const char *name)
+{
+  ARegion *ar = MEM_callocN(sizeof(ARegion), name);
+  ar->regiontype = regiontype;
+  return ar;
+}
+
 void do_versions_after_linking_280(Main *bmain)
 {
   bool use_collection_compat_28 = true;
@@ -3013,31 +3042,16 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
           if (sl->spacetype == SPACE_TEXT) {
             ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
-            ARegion *ar = MEM_callocN(sizeof(ARegion), "footer for text");
 
             /* Remove multiple footers that were added by mistake. */
-            ARegion *ar_footer, *ar_next;
-            for (ar_footer = regionbase->first; ar_footer; ar_footer = ar_next) {
-              ar_next = ar_footer->next;
-              if (ar_footer->regiontype == RGN_TYPE_FOOTER) {
-                BLI_freelinkN(regionbase, ar_footer);
-              }
-            }
+            do_versions_remove_region(regionbase, RGN_TYPE_HEADER);
 
             /* Add footer. */
-            ARegion *ar_header = NULL;
-
-            for (ar_header = regionbase->first; ar_header; ar_header = ar_header->next) {
-              if (ar_header->regiontype == RGN_TYPE_HEADER) {
-                break;
-              }
-            }
-            BLI_assert(ar_header);
+            ARegion *ar = do_versions_add_region(RGN_TYPE_FOOTER, "footer for text");
+            ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_TOP : RGN_ALIGN_BOTTOM;
 
+            ARegion *ar_header = do_versions_find_region(regionbase, RGN_TYPE_HEADER);
             BLI_insertlinkafter(regionbase, ar_header, ar);
-
-            ar->regiontype = RGN_TYPE_FOOTER;
-            ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_TOP : RGN_ALIGN_BOTTOM;
           }
         }
       }



More information about the Bf-blender-cvs mailing list