]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid duplicate comparison in describe_map_compare
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 12 Jul 2019 00:01:20 +0000 (17:01 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 12 Jul 2019 00:04:55 +0000 (17:04 -0700)
* src/fns.c (string_version_cmp): New function.
This has most of the old Fstring_version_lessp,
with an assertion to make things a bit clearer.
* src/fns.c (Fstring_version_lessp):
* src/keymap.c (describe_map_compare): Use it (Bug#33237).

src/fns.c
src/keymap.c
src/lisp.h

index 7343556ac21ca98ef722916ce95ec10282e10c49..a61801bc77d7ca60d1191ffe7cc09ad90444ff6c 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -403,7 +403,14 @@ Symbols are also allowed; their print names are used instead.  */)
     string2 = SYMBOL_NAME (string2);
   CHECK_STRING (string1);
   CHECK_STRING (string2);
+  return string_version_cmp (string1, string2) < 0 ? Qt : Qnil;
+}
 
+/* Return negative, 0, positive if STRING1 is <, =, > STRING2 as per
+   string-version-lessp.  */
+int
+string_version_cmp (Lisp_Object string1, Lisp_Object string2)
+{
   char *p1 = SSDATA (string1);
   char *p2 = SSDATA (string2);
   char *lim1 = p1 + SBYTES (string1);
@@ -415,15 +422,18 @@ Symbols are also allowed; their print names are used instead.  */)
       /* If the strings are identical through their first NUL bytes,
         skip past identical prefixes and try again.  */
       ptrdiff_t size = strlen (p1) + 1;
+      eassert (size == strlen (p2) + 1);
       p1 += size;
       p2 += size;
-      if (lim1 < p1)
-       return lim2 < p2 ? Qnil : Qt;
-      if (lim2 < p2)
-       return Qnil;
+      bool more1 = p1 <= lim1;
+      bool more2 = p2 <= lim2;
+      if (!more1)
+       return more2;
+      if (!more2)
+       return -1;
     }
 
-  return cmp < 0 ? Qt : Qnil;
+  return cmp;
 }
 
 DEFUN ("string-collate-lessp", Fstring_collate_lessp, Sstring_collate_lessp, 2, 4, 0,
index fc04c565a1e529c98ad2ed5ae8cae46779d32d2a..6762915f70cf2d9cafbdd89a08ab81652d0d0342 100644 (file)
@@ -3100,9 +3100,7 @@ describe_map_compare (const void *aa, const void *bb)
   if (SYMBOLP (a->event) && SYMBOLP (b->event))
     /* Sort the keystroke names in the "natural" way, with (for
        instance) "<f2>" coming between "<f1>" and "<f11>".  */
-    return (!NILP (Fstring_version_lessp (a->event, b->event)) ? -1
-           : !NILP (Fstring_version_lessp (b->event, a->event)) ? 1
-           : 0);
+    return string_version_cmp (SYMBOL_NAME (a->event), SYMBOL_NAME (b->event));
   return 0;
 }
 
index fa57cad8a6000709d8da61ad208aa518195cb713..7641b2aab4d09be69623b3ed44615f9642d3d256 100644 (file)
@@ -3595,6 +3595,7 @@ extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
                                   ptrdiff_t, ptrdiff_t);
 extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object);
 extern Lisp_Object do_yes_or_no_p (Lisp_Object);
+extern int string_version_cmp (Lisp_Object, Lisp_Object);
 extern Lisp_Object concat2 (Lisp_Object, Lisp_Object);
 extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object);
 extern bool equal_no_quit (Lisp_Object, Lisp_Object);