aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorDaniel Colascione2014-04-21 20:51:12 -0700
committerDaniel Colascione2014-04-21 20:51:12 -0700
commit66fda7948f7d0b94194d53edcfbf27bec596c019 (patch)
tree5e24a63483e983e426a44bfa6b5629b28e3be6f4 /lisp
parentd6f14ca729315dd94cdb24da47e1569519e3a4dd (diff)
downloademacs-66fda7948f7d0b94194d53edcfbf27bec596c019.tar.gz
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')
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/emacs-lisp/cl-macs.el9
2 files changed, 15 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5d96e867072..c4b1c051210 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12014-04-22 Daniel Colascione <dancol@dancol.org>
2
3 * emacs-lisp/cl-macs.el
4 (cl-struct-sequence-type,cl-struct-slot-info): Declare pure.
5 (cl-struct-slot-value): Conditionally use aref or nth so that the
6 compiler produces optimal code.
7
12014-04-22 Stefan Monnier <monnier@iro.umontreal.ca> 82014-04-22 Stefan Monnier <monnier@iro.umontreal.ca>
2 9
3 * emacs-lisp/cl-macs.el (cl-struct-slot-offset): Mark as pure. 10 * emacs-lisp/cl-macs.el (cl-struct-slot-offset): Mark as pure.
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
2600'list, or nil if STRUCT-TYPE is not a struct type. " 2600'list, or nil if STRUCT-TYPE is not a struct type. "
2601 (car (get struct-type 'cl-struct-type))) 2601 (car (get struct-type 'cl-struct-type)))
2602(put 'cl-struct-sequence-type 'side-effect-free t) 2602(put 'cl-struct-sequence-type 'side-effect-free t)
2603(put 'cl-struct-sequence-type 'pure t)
2603 2604
2604(defun cl-struct-slot-info (struct-type) 2605(defun cl-struct-slot-info (struct-type)
2605 "Return a list of slot names of struct STRUCT-TYPE. 2606 "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
2609slots skipped by :initial-offset may appear in the list." 2610slots skipped by :initial-offset may appear in the list."
2610 (get struct-type 'cl-struct-slots)) 2611 (get struct-type 'cl-struct-slots))
2611(put 'cl-struct-slot-info 'side-effect-free t) 2612(put 'cl-struct-slot-info 'side-effect-free t)
2613(put 'cl-struct-slot-info 'pure t)
2612 2614
2613(defun cl-struct-slot-offset (struct-type slot-name) 2615(defun cl-struct-slot-offset (struct-type slot-name)
2614 "Return the offset of slot SLOT-NAME in STRUCT-TYPE. 2616 "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."
2942STRUCT and SLOT-NAME are symbols. INST is a structure instance." 2944STRUCT and SLOT-NAME are symbols. INST is a structure instance."
2943 (unless (cl-typep inst struct-type) 2945 (unless (cl-typep inst struct-type)
2944 (signal 'wrong-type-argument (list struct-type inst))) 2946 (signal 'wrong-type-argument (list struct-type inst)))
2945 (elt inst (cl-struct-slot-offset struct-type slot-name))) 2947 ;; We could use `elt', but since the byte compiler will resolve the
2948 ;; branch below at compile time, it's more efficient to use the
2949 ;; type-specific accessor.
2950 (if (eq (cl-struct-sequence-type struct-type) 'vector)
2951 (aref inst (cl-struct-slot-offset struct-type slot-name))
2952 (nth (cl-struct-slot-offset struct-type slot-name) inst)))
2946(put 'cl-struct-slot-value 'side-effect-free t) 2953(put 'cl-struct-slot-value 'side-effect-free t)
2947 2954
2948(run-hooks 'cl-macs-load-hook) 2955(run-hooks 'cl-macs-load-hook)