[Bf-blender-cvs] [020431408f1] master: Cleanup: limit scope of temporary variables

Campbell Barton noreply at git.blender.org
Fri Jul 30 08:45:49 CEST 2021


Commit: 020431408f12ab7e1c3024e08a4067dce0ae2433
Author: Campbell Barton
Date:   Fri Jul 30 16:43:47 2021 +1000
Branches: master
https://developer.blender.org/rB020431408f12ab7e1c3024e08a4067dce0ae2433

Cleanup: limit scope of temporary variables

Also remove early return as it duplicates cleanup calls.

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

M	source/blender/editors/interface/view2d_draw.c

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

diff --git a/source/blender/editors/interface/view2d_draw.c b/source/blender/editors/interface/view2d_draw.c
index 1496ce027ae..95427e49495 100644
--- a/source/blender/editors/interface/view2d_draw.c
+++ b/source/blender/editors/interface/view2d_draw.c
@@ -329,29 +329,28 @@ static void draw_horizontal_scale_indicators(const ARegion *region,
   char text[32];
 
   /* Calculate max_label_count and draw_frequency based on largest visible label. */
-  to_string(to_string_data, start, 0, sizeof(text), text);
-  const float left_text_width = BLF_width(font_id, text, strlen(text));
-  to_string(to_string_data, start + steps * distance, 0, sizeof(text), text);
-  const float right_text_width = BLF_width(font_id, text, strlen(text));
-  const float max_text_width = max_ff(left_text_width, right_text_width);
-  const float max_label_count = BLI_rcti_size_x(&v2d->mask) / (max_text_width + 10.0f);
-  const int draw_frequency = ceil((float)steps / max_label_count);
-
-  if (draw_frequency == 0) {
-    BLF_batch_draw_end();
-    GPU_matrix_pop_projection();
-    return;
-  }
-
-  const int start_index = abs((int)(start / distance)) % draw_frequency;
-  for (uint i = start_index; i < steps; i += draw_frequency) {
-    const float xpos_view = start + i * distance;
-    const float xpos_region = UI_view2d_view_to_region_x(v2d, xpos_view);
-    to_string(to_string_data, xpos_view, distance, sizeof(text), text);
-    const float text_width = BLF_width(font_id, text, strlen(text));
-
-    if (xpos_region - text_width / 2.0f >= xmin && xpos_region + text_width / 2.0f <= xmax) {
-      BLF_draw_default_ascii(xpos_region - text_width / 2.0f, ypos, 0.0f, text, sizeof(text));
+  int draw_frequency;
+  {
+    to_string(to_string_data, start, 0, sizeof(text), text);
+    const float left_text_width = BLF_width(font_id, text, strlen(text));
+    to_string(to_string_data, start + steps * distance, 0, sizeof(text), text);
+    const float right_text_width = BLF_width(font_id, text, strlen(text));
+    const float max_text_width = max_ff(left_text_width, right_text_width);
+    const float max_label_count = BLI_rcti_size_x(&v2d->mask) / (max_text_width + 10.0f);
+    draw_frequency = ceil((float)steps / max_label_count);
+  }
+
+  if (draw_frequency != 0) {
+    const int start_index = abs((int)(start / distance)) % draw_frequency;
+    for (uint i = start_index; i < steps; i += draw_frequency) {
+      const float xpos_view = start + i * distance;
+      const float xpos_region = UI_view2d_view_to_region_x(v2d, xpos_view);
+      to_string(to_string_data, xpos_view, distance, sizeof(text), text);
+      const float text_width = BLF_width(font_id, text, strlen(text));
+
+      if (xpos_region - text_width / 2.0f >= xmin && xpos_region + text_width / 2.0f <= xmax) {
+        BLF_draw_default_ascii(xpos_region - text_width / 2.0f, ypos, 0.0f, text, sizeof(text));
+      }
     }
   }



More information about the Bf-blender-cvs mailing list