]> git.eshelyaron.com Git - emacs.git/commitdiff
* Add 'cl-optimize' as function declaration
authorAndrea Corallo <akrl@sdf.org>
Mon, 14 Sep 2020 19:06:54 +0000 (21:06 +0200)
committerAndrea Corallo <akrl@sdf.org>
Mon, 14 Sep 2020 21:06:42 +0000 (23:06 +0200)
* lisp/emacs-lisp/cl-macs.el: Register cl-optimize into
`defun-declarations-alist' and `macro-declarations-alist'.
(cl--optimize): New function to serve 'cl-optimize' declaration.

lisp/emacs-lisp/cl-macs.el

index 7adb9100703d93a08bba31fa61a2d7a26598a56b..2730e8f24a3ad8536c5d4a1b29576a650b7d38ba 100644 (file)
@@ -2347,6 +2347,26 @@ values.  For compatibility, (cl-values A B C) is a synonym for (list A B C).
                         (list ',type ,temp ',form)))
               ,temp))))
 
+;;;###autoload
+(or (assq 'cl-optimize defun-declarations-alist)
+    (let ((x (list 'cl-optimize #'cl--optimize)))
+      (push x macro-declarations-alist)
+      (push x defun-declarations-alist)))
+
+(defun cl--optimize (f _args &rest qualities)
+  "Serve 'cl-optimize' in function declarations.
+Example:
+(defun foo (x)
+  (declare (cl-optimize (speed 3) (safety 0)))
+  x)"
+  (cl-loop for (qly val) in qualities
+           do (cl-ecase qly
+                (speed
+                 (setf cl--optimize-speed val)
+                 (byte-run--set-speed f nil val))
+                (safety
+                 (setf cl--optimize-safety val)))))
+
 (defvar cl--proclaim-history t)    ; for future compilers
 (defvar cl--declare-stack t)       ; for future compilers