diff options
author | Daniel Colascione <dancol@dancol.org> | 2014-04-21 20:51:12 -0700 |
---|---|---|
committer | Daniel Colascione <dancol@dancol.org> | 2014-04-21 20:51:12 -0700 |
commit | 66fda7948f7d0b94194d53edcfbf27bec596c019 (patch) | |
tree | 5e24a63483e983e426a44bfa6b5629b28e3be6f4 /lisp/emacs-lisp | |
parent | d6f14ca729315dd94cdb24da47e1569519e3a4dd (diff) | |
download | emacs-66fda7948f7d0b94194d53edcfbf27bec596c019.tar.gz emacs-66fda7948f7d0b94194d53edcfbf27bec596c019.tar.bz2 emacs-66fda7948f7d0b94194d53edcfbf27bec596c019.zip |
Optimize cl-struct-slot-value; fix test
2014-04-22 Daniel Colascione <dancol@dancol.org>
* emacs-lisp/cl-macs.el
(cl-struct-sequence-type,cl-struct-slot-info): Declare pure.
(cl-struct-slot-value): Conditionally use aref or nth so that the
compiler produces optimal code.
2014-04-22 Daniel Colascione <dancol@dancol.org>
* automated/cl-lib.el (cl-lib-struct-accessors): Fix test to
account for removal of `cl-struct-set-slot-value'.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index a15918d262f..47a89d0880b 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -2600,6 +2600,7 @@ STRUCT-TYPE is a symbol naming a struct type. Return 'vector or 'list, or nil if STRUCT-TYPE is not a struct type. " (car (get struct-type 'cl-struct-type))) (put 'cl-struct-sequence-type 'side-effect-free t) +(put 'cl-struct-sequence-type 'pure t) (defun cl-struct-slot-info (struct-type) "Return a list of slot names of struct STRUCT-TYPE. @@ -2609,6 +2610,7 @@ slot name symbol and OPTS is a list of slot options given to slots skipped by :initial-offset may appear in the list." (get struct-type 'cl-struct-slots)) (put 'cl-struct-slot-info 'side-effect-free t) +(put 'cl-struct-slot-info 'pure t) (defun cl-struct-slot-offset (struct-type slot-name) "Return the offset of slot SLOT-NAME in STRUCT-TYPE. @@ -2942,7 +2944,12 @@ The type name can then be used in `cl-typecase', `cl-check-type', etc." STRUCT and SLOT-NAME are symbols. INST is a structure instance." (unless (cl-typep inst struct-type) (signal 'wrong-type-argument (list struct-type inst))) - (elt inst (cl-struct-slot-offset struct-type slot-name))) + ;; We could use `elt', but since the byte compiler will resolve the + ;; branch below at compile time, it's more efficient to use the + ;; type-specific accessor. + (if (eq (cl-struct-sequence-type struct-type) 'vector) + (aref inst (cl-struct-slot-offset struct-type slot-name)) + (nth (cl-struct-slot-offset struct-type slot-name) inst))) (put 'cl-struct-slot-value 'side-effect-free t) (run-hooks 'cl-macs-load-hook) |