Function: defsubst
defsubst is a macro defined in byte-run.el.gz.
Signature
(defsubst NAME ARGLIST &optional DOCSTRING DECL &rest BODY)
Documentation
Define an inline function. The syntax is just like that of defun.
Probably introduced at or before Emacs version 30.1.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/byte-run.el.gz
;;; Interface to inline functions.
;; (defmacro proclaim-inline (&rest fns)
;; "Cause the named functions to be open-coded when called from compiled code.
;; They will only be compiled open-coded when byte-compile-optimize is true."
;; (cons 'eval-and-compile
;; (mapcar (lambda (x)
;; (or (memq (get x 'byte-optimizer)
;; '(nil byte-compile-inline-expand))
;; (error
;; "%s already has a byte-optimizer, can't make it inline"
;; x))
;; (list 'put (list 'quote x)
;; ''byte-optimizer ''byte-compile-inline-expand))
;; fns)))
;; (defmacro proclaim-notinline (&rest fns)
;; "Cause the named functions to no longer be open-coded."
;; (cons 'eval-and-compile
;; (mapcar (lambda (x)
;; (if (eq (get x 'byte-optimizer) 'byte-compile-inline-expand)
;; (put x 'byte-optimizer nil))
;; (list 'if (list 'eq (list 'get (list 'quote x) ''byte-optimizer)
;; ''byte-compile-inline-expand)
;; (list 'put x ''byte-optimizer nil)))
;; fns)))
(defmacro defsubst (name arglist &rest body)
"Define an inline function. The syntax is just like that of `defun'.
\(fn NAME ARGLIST &optional DOCSTRING DECL &rest BODY)"
(declare (debug defun) (doc-string 3) (indent 2))
(or (memq (get name 'byte-optimizer)
'(nil byte-compile-inline-expand))
(error "`%s' is a primitive" name))
`(prog1
(defun ,name ,arglist ,@body)
(eval-and-compile
;; Never native-compile defsubsts as we need the byte
;; definition in `byte-compile-unfold-bcf' to perform the
;; inlining (Bug#42664, Bug#43280, Bug#44209).
,(byte-run--set-speed name nil -1)
(put ',name 'byte-optimizer 'byte-compile-inline-expand))))