]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0223: code duplication in loop to add active text properties v9.1.0223
authorDylan Thacker-Smith <dylan.ah.smith@gmail.com>
Thu, 28 Mar 2024 10:49:46 +0000 (11:49 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 28 Mar 2024 10:51:10 +0000 (11:51 +0100)
Problem:  There are two dense conditions with duplication that needs to
          be kept in sync between the while loop break condition and the
          condition to skip certain text properties.
Solution: Refactor the loop by moving while loop conditions into the
          body of the while loop so they can be shared with skip
          conditions. `break` and an `active` variable are used to
          handle the outcome of these merged conditions.
          (Dylan Thacker-Smith)

closes: #14307

Signed-off-by: Dylan Thacker-Smith <dylan.ah.smith@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/drawline.c
src/version.c

index 8ec9e5f2800bf99dd9a8f10d4ff9216cb23cd235..81577be42a52aa835d3596f2f87ea60215123870 100644 (file)
@@ -2073,29 +2073,34 @@ win_line(
                    --bcol;
 # endif
                // Add any text property that starts in this column.
-               while (text_prop_next < text_prop_count
-                          && (text_props[text_prop_next].tp_col == MAXCOL
-                             ? (*ptr == NUL
-                              || (bcol == 0
-                                       && (text_props[text_prop_next].tp_flags
-                                                      & TP_FLAG_ALIGN_ABOVE)))
-                             : bcol >= text_props[text_prop_next].tp_col - 1))
+               while (text_prop_next < text_prop_count)
                {
-                   // With 'nowrap' and not in the first screen line only "below"
-                   // text prop can show.
-                   if (text_props[text_prop_next].tp_col == MAXCOL
-                           ? (wp->w_p_wrap
+                   int active;
+                   textprop_T *tp = &text_props[text_prop_next];
+                   if (tp->tp_col == MAXCOL)
+                   {
+                       if (bcol == 0 && (tp->tp_flags & TP_FLAG_ALIGN_ABOVE))
+                           active = TRUE;
+                       else if (*ptr != NUL)
+                           break;
+                       else
+                       {
+                           // With 'nowrap' and not in the first screen line only "below"
+                           // text prop can show.
+                           active = wp->w_p_wrap
                                  || wlv.row == startrow
-                                 || (text_props[text_prop_next].tp_flags
-                                       & TP_FLAG_ALIGN_BELOW)
-                                 || (bcol == 0
-                                       && (text_props[text_prop_next].tp_flags
-                                                      & TP_FLAG_ALIGN_ABOVE)))
-                           : bcol <= text_props[text_prop_next].tp_col - 1
-                                          + text_props[text_prop_next].tp_len)
+                                 || (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
+                       }
+                   }
+                   else
                    {
-                       text_prop_idxs[text_props_active++] = text_prop_next;
+                       if (bcol < tp->tp_col - 1)
+                           break;
+                       active = bcol <= tp->tp_col - 1 + tp->tp_len;
                    }
+
+                   if (active)
+                       text_prop_idxs[text_props_active++] = text_prop_next;
                    ++text_prop_next;
                }
 
index 3fcbb9981132c2e39cf492d8ffc81097e851b239..7176d67b06edf62e55d25ad1a3f03c3b1325db73 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    223,
 /**/
     222,
 /**/