1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-13 02:12:18 -07:00

Implement string> as a compiler macro instead of an optimisation

This doesn't affect the generated code.

* lisp/subr.el (string-greaterp): Add compiler macro.
* lisp/emacs-lisp/byte-opt.el (byte-optimize-string-greaterp): Remove.
This commit is contained in:
Mattias Engdegård 2026-02-27 14:52:20 +01:00
parent 9d9f7b2c48
commit 460e438356
2 changed files with 4 additions and 11 deletions

View file

@ -1179,14 +1179,6 @@ See Info node `(elisp) Integer Basics'."
form ; No improvement.
(cons 'concat (nreverse newargs)))))
(defun byte-optimize-string-greaterp (form)
;; Rewrite in terms of `string-lessp' which has its own bytecode.
(pcase (cdr form)
(`(,a ,b) (let ((arg1 (make-symbol "arg1")))
`(let ((,arg1 ,a))
(string-lessp ,b ,arg1))))
(_ form)))
(put 'identity 'byte-optimizer #'byte-optimize-identity)
(put 'memq 'byte-optimizer #'byte-optimize-memq)
(put 'memql 'byte-optimizer #'byte-optimize-member)
@ -1214,8 +1206,6 @@ See Info node `(elisp) Integer Basics'."
(put '> 'byte-optimizer #'byte-opt--nary-comparison)
(put '>= 'byte-optimizer #'byte-opt--nary-comparison)
(put 'string-greaterp 'byte-optimizer #'byte-optimize-string-greaterp)
(put 'concat 'byte-optimizer #'byte-optimize-concat)
;; I'm not convinced that this is necessary. Doesn't the optimizer loop

View file

@ -6222,7 +6222,10 @@ consisting of STR followed by an invisible left-to-right mark
"Return non-nil if STRING1 is greater than STRING2 in lexicographic order.
Case is significant.
Symbols are also allowed; their print names are used instead."
(declare (pure t) (side-effect-free t))
(declare (compiler-macro (lambda (_)
(let ((arg1 (make-symbol "arg1")))
`(let ((,arg1 ,string1))
(string-lessp ,string2 ,arg1))))))
(string-lessp string2 string1))