aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2015-10-10 00:17:11 -0700
committerPaul Eggert2015-10-10 00:18:39 -0700
commitbb7c182fdaf8553ffdc9162f322177ae2f7fa0c2 (patch)
tree444b1eef3d424cb5b07396a11bc66fe401d0a1dd
parent1196e3fca6f9df107c76438b7d00090d19b13570 (diff)
downloademacs-bb7c182fdaf8553ffdc9162f322177ae2f7fa0c2.tar.gz
emacs-bb7c182fdaf8553ffdc9162f322177ae2f7fa0c2.zip
CHECK_IMPURE and PURE_P speedup
* src/intervals.c (create_root_interval): Do CHECK_IMPURE only for strings; not needed for buffers. Prefer ! STRINGP to BUFFERP, for a tad more speed. * src/puresize.h (CHECK_IMPURE, PURE_P): Now inline functions instead of macros. (PURE_P): Don’t use XPNTR; that is now the caller’s responsibility. All callers changed. (CHECK_IMPURE): New argument PTR, to save us the work of running XPNTR. All callers changed.
-rw-r--r--src/data.c6
-rw-r--r--src/intervals.c9
-rw-r--r--src/keymap.c10
-rw-r--r--src/puresize.h23
4 files changed, 26 insertions, 22 deletions
diff --git a/src/data.c b/src/data.c
index eda611055d8..5ee40c54040 100644
--- a/src/data.c
+++ b/src/data.c
@@ -560,7 +560,7 @@ DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0,
560 (register Lisp_Object cell, Lisp_Object newcar) 560 (register Lisp_Object cell, Lisp_Object newcar)
561{ 561{
562 CHECK_CONS (cell); 562 CHECK_CONS (cell);
563 CHECK_IMPURE (cell); 563 CHECK_IMPURE (cell, XCONS (cell));
564 XSETCAR (cell, newcar); 564 XSETCAR (cell, newcar);
565 return newcar; 565 return newcar;
566} 566}
@@ -570,7 +570,7 @@ DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0,
570 (register Lisp_Object cell, Lisp_Object newcdr) 570 (register Lisp_Object cell, Lisp_Object newcdr)
571{ 571{
572 CHECK_CONS (cell); 572 CHECK_CONS (cell);
573 CHECK_IMPURE (cell); 573 CHECK_IMPURE (cell, XCONS (cell));
574 XSETCDR (cell, newcdr); 574 XSETCDR (cell, newcdr);
575 return newcdr; 575 return newcdr;
576} 576}
@@ -2215,7 +2215,7 @@ bool-vector. IDX starts at 0. */)
2215 CHECK_NUMBER (idx); 2215 CHECK_NUMBER (idx);
2216 idxval = XINT (idx); 2216 idxval = XINT (idx);
2217 CHECK_ARRAY (array, Qarrayp); 2217 CHECK_ARRAY (array, Qarrayp);
2218 CHECK_IMPURE (array); 2218 CHECK_IMPURE (array, XVECTOR (array));
2219 2219
2220 if (VECTORP (array)) 2220 if (VECTORP (array))
2221 { 2221 {
diff --git a/src/intervals.c b/src/intervals.c
index 78e0f50f6fe..1c8dd41e6a2 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -91,11 +91,9 @@ create_root_interval (Lisp_Object parent)
91{ 91{
92 INTERVAL new; 92 INTERVAL new;
93 93
94 CHECK_IMPURE (parent);
95
96 new = make_interval (); 94 new = make_interval ();
97 95
98 if (BUFFERP (parent)) 96 if (! STRINGP (parent))
99 { 97 {
100 new->total_length = (BUF_Z (XBUFFER (parent)) 98 new->total_length = (BUF_Z (XBUFFER (parent))
101 - BUF_BEG (XBUFFER (parent))); 99 - BUF_BEG (XBUFFER (parent)));
@@ -103,15 +101,16 @@ create_root_interval (Lisp_Object parent)
103 set_buffer_intervals (XBUFFER (parent), new); 101 set_buffer_intervals (XBUFFER (parent), new);
104 new->position = BEG; 102 new->position = BEG;
105 } 103 }
106 else if (STRINGP (parent)) 104 else
107 { 105 {
106 CHECK_IMPURE (parent, XSTRING (parent));
108 new->total_length = SCHARS (parent); 107 new->total_length = SCHARS (parent);
109 eassert (TOTAL_LENGTH (new) >= 0); 108 eassert (TOTAL_LENGTH (new) >= 0);
110 set_string_intervals (parent, new); 109 set_string_intervals (parent, new);
111 new->position = 0; 110 new->position = 0;
112 } 111 }
113 eassert (LENGTH (new) > 0); 112 eassert (LENGTH (new) > 0);
114 113
115 set_interval_object (new, parent); 114 set_interval_object (new, parent);
116 115
117 return new; 116 return new;
diff --git a/src/keymap.c b/src/keymap.c
index 6a8d129ce2b..81091f03d70 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -341,7 +341,7 @@ Return PARENT. PARENT should be nil or another keymap. */)
341 If we came to the end, add the parent in PREV. */ 341 If we came to the end, add the parent in PREV. */
342 if (!CONSP (list) || KEYMAPP (list)) 342 if (!CONSP (list) || KEYMAPP (list))
343 { 343 {
344 CHECK_IMPURE (prev); 344 CHECK_IMPURE (prev, XCONS (prev));
345 XSETCDR (prev, parent); 345 XSETCDR (prev, parent);
346 return parent; 346 return parent;
347 } 347 }
@@ -750,7 +750,7 @@ store_in_keymap (Lisp_Object keymap, register Lisp_Object idx, Lisp_Object def)
750 750
751 /* If we are preparing to dump, and DEF is a menu element 751 /* If we are preparing to dump, and DEF is a menu element
752 with a menu item indicator, copy it to ensure it is not pure. */ 752 with a menu item indicator, copy it to ensure it is not pure. */
753 if (CONSP (def) && PURE_P (def) 753 if (CONSP (def) && PURE_P (XCONS (def))
754 && (EQ (XCAR (def), Qmenu_item) || STRINGP (XCAR (def)))) 754 && (EQ (XCAR (def), Qmenu_item) || STRINGP (XCAR (def))))
755 def = Fcons (XCAR (def), XCDR (def)); 755 def = Fcons (XCAR (def), XCDR (def));
756 756
@@ -798,7 +798,7 @@ store_in_keymap (Lisp_Object keymap, register Lisp_Object idx, Lisp_Object def)
798 { 798 {
799 if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (elt)) 799 if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (elt))
800 { 800 {
801 CHECK_IMPURE (elt); 801 CHECK_IMPURE (elt, XVECTOR (elt));
802 ASET (elt, XFASTINT (idx), def); 802 ASET (elt, XFASTINT (idx), def);
803 return def; 803 return def;
804 } 804 }
@@ -851,7 +851,7 @@ store_in_keymap (Lisp_Object keymap, register Lisp_Object idx, Lisp_Object def)
851 } 851 }
852 else if (EQ (idx, XCAR (elt))) 852 else if (EQ (idx, XCAR (elt)))
853 { 853 {
854 CHECK_IMPURE (elt); 854 CHECK_IMPURE (elt, XCONS (elt));
855 XSETCDR (elt, def); 855 XSETCDR (elt, def);
856 return def; 856 return def;
857 } 857 }
@@ -895,7 +895,7 @@ store_in_keymap (Lisp_Object keymap, register Lisp_Object idx, Lisp_Object def)
895 } 895 }
896 else 896 else
897 elt = Fcons (idx, def); 897 elt = Fcons (idx, def);
898 CHECK_IMPURE (insertion_point); 898 CHECK_IMPURE (insertion_point, XCONS (insertion_point));
899 XSETCDR (insertion_point, Fcons (elt, XCDR (insertion_point))); 899 XSETCDR (insertion_point, Fcons (elt, XCDR (insertion_point)));
900 } 900 }
901 } 901 }
diff --git a/src/puresize.h b/src/puresize.h
index b72fb6c03f9..d0926c65213 100644
--- a/src/puresize.h
+++ b/src/puresize.h
@@ -70,16 +70,21 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
70#define PURESIZE (BASE_PURESIZE * PURESIZE_RATIO * PURESIZE_CHECKING_RATIO) 70#define PURESIZE (BASE_PURESIZE * PURESIZE_RATIO * PURESIZE_CHECKING_RATIO)
71#endif 71#endif
72 72
73/* Signal an error if OBJ is pure. */
74#define CHECK_IMPURE(obj) \
75 { if (PURE_P (obj)) \
76 pure_write_error (obj); }
77
78extern _Noreturn void pure_write_error (Lisp_Object); 73extern _Noreturn void pure_write_error (Lisp_Object);
79
80/* Define PURE_P. */
81 74
82extern EMACS_INT pure[]; 75extern EMACS_INT pure[];
83 76
84#define PURE_P(obj) \ 77/* True if PTR is pure. */
85 ((uintptr_t) XPNTR (obj) - (uintptr_t) pure <= PURESIZE) 78INLINE bool
79PURE_P (void *ptr)
80{
81 return (uintptr_t) (ptr) - (uintptr_t) pure <= PURESIZE;
82}
83
84/* Signal an error if OBJ is pure. PTR is OBJ untagged. */
85INLINE void
86CHECK_IMPURE (Lisp_Object obj, void *ptr)
87{
88 if (PURE_P (ptr))
89 pure_write_error (obj);
90}