diff options
| author | Paul Eggert | 2019-07-11 17:01:20 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-07-11 17:04:55 -0700 |
| commit | 77a4cc9f1a7df97c9a11195dcf6e90c8820be9bb (patch) | |
| tree | b33ccaa9f460662eea0884bd043fa873cdf38a1e /src | |
| parent | ef6715364dd94f98dcdf60ff295c89ac856de882 (diff) | |
| download | emacs-77a4cc9f1a7df97c9a11195dcf6e90c8820be9bb.tar.gz emacs-77a4cc9f1a7df97c9a11195dcf6e90c8820be9bb.zip | |
Avoid duplicate comparison in describe_map_compare
* 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).
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 20 | ||||
| -rw-r--r-- | src/keymap.c | 4 | ||||
| -rw-r--r-- | src/lisp.h | 1 |
3 files changed, 17 insertions, 8 deletions
| @@ -403,7 +403,14 @@ Symbols are also allowed; their print names are used instead. */) | |||
| 403 | string2 = SYMBOL_NAME (string2); | 403 | string2 = SYMBOL_NAME (string2); |
| 404 | CHECK_STRING (string1); | 404 | CHECK_STRING (string1); |
| 405 | CHECK_STRING (string2); | 405 | CHECK_STRING (string2); |
| 406 | return string_version_cmp (string1, string2) < 0 ? Qt : Qnil; | ||
| 407 | } | ||
| 406 | 408 | ||
| 409 | /* Return negative, 0, positive if STRING1 is <, =, > STRING2 as per | ||
| 410 | string-version-lessp. */ | ||
| 411 | int | ||
| 412 | string_version_cmp (Lisp_Object string1, Lisp_Object string2) | ||
| 413 | { | ||
| 407 | char *p1 = SSDATA (string1); | 414 | char *p1 = SSDATA (string1); |
| 408 | char *p2 = SSDATA (string2); | 415 | char *p2 = SSDATA (string2); |
| 409 | char *lim1 = p1 + SBYTES (string1); | 416 | char *lim1 = p1 + SBYTES (string1); |
| @@ -415,15 +422,18 @@ Symbols are also allowed; their print names are used instead. */) | |||
| 415 | /* If the strings are identical through their first NUL bytes, | 422 | /* If the strings are identical through their first NUL bytes, |
| 416 | skip past identical prefixes and try again. */ | 423 | skip past identical prefixes and try again. */ |
| 417 | ptrdiff_t size = strlen (p1) + 1; | 424 | ptrdiff_t size = strlen (p1) + 1; |
| 425 | eassert (size == strlen (p2) + 1); | ||
| 418 | p1 += size; | 426 | p1 += size; |
| 419 | p2 += size; | 427 | p2 += size; |
| 420 | if (lim1 < p1) | 428 | bool more1 = p1 <= lim1; |
| 421 | return lim2 < p2 ? Qnil : Qt; | 429 | bool more2 = p2 <= lim2; |
| 422 | if (lim2 < p2) | 430 | if (!more1) |
| 423 | return Qnil; | 431 | return more2; |
| 432 | if (!more2) | ||
| 433 | return -1; | ||
| 424 | } | 434 | } |
| 425 | 435 | ||
| 426 | return cmp < 0 ? Qt : Qnil; | 436 | return cmp; |
| 427 | } | 437 | } |
| 428 | 438 | ||
| 429 | DEFUN ("string-collate-lessp", Fstring_collate_lessp, Sstring_collate_lessp, 2, 4, 0, | 439 | DEFUN ("string-collate-lessp", Fstring_collate_lessp, Sstring_collate_lessp, 2, 4, 0, |
diff --git a/src/keymap.c b/src/keymap.c index fc04c565a1e..6762915f70c 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -3100,9 +3100,7 @@ describe_map_compare (const void *aa, const void *bb) | |||
| 3100 | if (SYMBOLP (a->event) && SYMBOLP (b->event)) | 3100 | if (SYMBOLP (a->event) && SYMBOLP (b->event)) |
| 3101 | /* Sort the keystroke names in the "natural" way, with (for | 3101 | /* Sort the keystroke names in the "natural" way, with (for |
| 3102 | instance) "<f2>" coming between "<f1>" and "<f11>". */ | 3102 | instance) "<f2>" coming between "<f1>" and "<f11>". */ |
| 3103 | return (!NILP (Fstring_version_lessp (a->event, b->event)) ? -1 | 3103 | return string_version_cmp (SYMBOL_NAME (a->event), SYMBOL_NAME (b->event)); |
| 3104 | : !NILP (Fstring_version_lessp (b->event, a->event)) ? 1 | ||
| 3105 | : 0); | ||
| 3106 | return 0; | 3104 | return 0; |
| 3107 | } | 3105 | } |
| 3108 | 3106 | ||
diff --git a/src/lisp.h b/src/lisp.h index fa57cad8a60..7641b2aab4d 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3595,6 +3595,7 @@ extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t, | |||
| 3595 | ptrdiff_t, ptrdiff_t); | 3595 | ptrdiff_t, ptrdiff_t); |
| 3596 | extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object); | 3596 | extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object); |
| 3597 | extern Lisp_Object do_yes_or_no_p (Lisp_Object); | 3597 | extern Lisp_Object do_yes_or_no_p (Lisp_Object); |
| 3598 | extern int string_version_cmp (Lisp_Object, Lisp_Object); | ||
| 3598 | extern Lisp_Object concat2 (Lisp_Object, Lisp_Object); | 3599 | extern Lisp_Object concat2 (Lisp_Object, Lisp_Object); |
| 3599 | extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object); | 3600 | extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object); |
| 3600 | extern bool equal_no_quit (Lisp_Object, Lisp_Object); | 3601 | extern bool equal_no_quit (Lisp_Object, Lisp_Object); |