]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0945: sort() with a numeric option can be improved v9.2.0945
authorHirohito Higashi <h.east.727@gmail.com>
Wed, 12 Aug 2026 18:38:28 +0000 (18:38 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 12 Aug 2026 18:38:28 +0000 (18:38 +0000)
Problem:  The comments on the precomputed sort keys explain the code by
          contrasting it with the previous implementation, and one of
          them exceeds 80 columns (after v9.2.0937).
Solution: Drop the redundant comments and shorten the union member ones
          (Hirohito Higashi).

related: #21003
closes:  #21030

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/list.c
src/version.c

index 7926128743ca5d704809247028e7352791982b80..7d57b125c4901a3f11a8b17a395d09f60b37cdbf 100644 (file)
@@ -2077,13 +2077,12 @@ typedef struct
 {
     listitem_T *item;
     int                idx;
-    // Sort key precomputed once per item for the numeric compare modes, so
-    // item_compare() does not convert the value on every comparison.  Only
-    // valid when sortinfo->item_compare_keys_ready is set (the sort() path);
-    // uniq() passes a bare listitem_T pointer and must not read this.
+    // Sort key precomputed once per item for the numeric compare modes.
+    // Only valid when sortinfo->item_compare_keys_ready is set (the sort()
+    // path); uniq() passes a bare listitem_T pointer and must not read this.
     union {
-       varnumber_T     inum;   // for item_compare_numbers ("N")
-       double          fnum;   // for item_compare_numeric ("n") and _float ("f")
+       varnumber_T     inum;   // for "N"
+       double          fnum;   // for "n" and "f"
     } key;
 } sortItem_T;
 
@@ -2265,10 +2264,8 @@ item_compare2(const void *s1, const void *s2)
 }
 
 /*
- * Precompute the numeric sort key of each item, so that item_compare() can
- * compare the stored value instead of converting the item on every one of the
- * O(n log n) comparisons.  Only for the builtin numeric compare modes; each
- * key is computed exactly as item_compare() would have, once per item.
+ * Precompute the numeric sort key of each item.  Only for the builtin numeric
+ * compare modes; each key is computed exactly as item_compare() would have.
  */
     static void
 sort_compute_keys(sortItem_T *ptrs, long len, sortinfo_T *info)
@@ -2292,7 +2289,7 @@ sort_compute_keys(sortItem_T *ptrs, long len, sortinfo_T *info)
            typval_T    *tv = &ptrs[i].item->li_tv;
 
            // A string is compared as a single quote in numeric mode, which
-           // strtod() reads as 0; only numbers contribute a value.
+           // strtod() reads as 0.
            if (tv->v_type == VAR_STRING)
                ptrs[i].key.fnum = 0.0;
            else
@@ -2338,8 +2335,7 @@ do_sort(list_T *l, sortinfo_T *info)
     info->item_compare_func_err = FALSE;
     info->item_compare_keep_zero = FALSE;
     info->item_compare_keys_ready = FALSE;
-    // For the builtin numeric compares, precompute each item's key once
-    // instead of converting it on every comparison.
+
     if (info->item_compare_func == NULL && info->item_compare_partial == NULL
            && (info->item_compare_numbers || info->item_compare_float
                                                || info->item_compare_numeric))
index 6c636db9aabb667b925e000a39737eed9a5d588a..7eb3acd6290682f9e904c5efc1df68adea96391f 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    945,
 /**/
     944,
 /**/