diff options
| author | Paul Eggert | 2024-02-13 09:54:51 -0800 |
|---|---|---|
| committer | Paul Eggert | 2024-02-13 11:20:33 -0800 |
| commit | 473dac880105cf6055a185eb3b9764243f27697c (patch) | |
| tree | 919fe869c06f6d927613675a7b71905fd5787685 /src | |
| parent | 231af322b07447d87b4c250aa601219a4005d9a5 (diff) | |
| download | emacs-473dac880105cf6055a185eb3b9764243f27697c.tar.gz emacs-473dac880105cf6055a185eb3b9764243f27697c.zip | |
Remove lisp_h_XCONS etc
When configured with --enable-checking and compiled with gcc -O0,
these macros evaluated arguments multiple times, which made it too
easy to mistakenly write code that behaves differently when debugging.
This patch does not affect performance in normal builds.
In --enable-checking builds with gcc -O0 it slows down my usual
benchmark (remove all '*.elc’ files and then 'make') by 4.4%.
I hope that’s good enough; if not I can complicate the macros to
tune better for debugging builds.
* src/lisp.h (lisp_h_SET_SYMBOL_VAL, lisp_h_SYMBOL_VAL)
(lisp_h_XCONS): Remove, moving each definiens to the corresponding
inline function. All uses removed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lisp.h | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/lisp.h b/src/lisp.h index d1dcddcfb89..796c7867b4c 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -330,7 +330,8 @@ typedef EMACS_INT Lisp_Word; | |||
| 330 | without worrying about the implementations diverging, since | 330 | without worrying about the implementations diverging, since |
| 331 | lisp_h_OP defines the actual implementation. The lisp_h_OP macros | 331 | lisp_h_OP defines the actual implementation. The lisp_h_OP macros |
| 332 | are intended to be private to this include file, and should not be | 332 | are intended to be private to this include file, and should not be |
| 333 | used elsewhere. | 333 | used elsewhere. They should evaluate each argument exactly once, |
| 334 | so that they behave like their functional counterparts. | ||
| 334 | 335 | ||
| 335 | FIXME: Remove the lisp_h_OP macros, and define just the inline OP | 336 | FIXME: Remove the lisp_h_OP macros, and define just the inline OP |
| 336 | functions, once "gcc -Og" (new to GCC 4.8) or equivalent works well | 337 | functions, once "gcc -Og" (new to GCC 4.8) or equivalent works well |
| @@ -385,14 +386,9 @@ typedef EMACS_INT Lisp_Word; | |||
| 385 | & ((1 << INTTYPEBITS) - 1))) | 386 | & ((1 << INTTYPEBITS) - 1))) |
| 386 | #define lisp_h_FLOATP(x) TAGGEDP (x, Lisp_Float) | 387 | #define lisp_h_FLOATP(x) TAGGEDP (x, Lisp_Float) |
| 387 | #define lisp_h_NILP(x) BASE_EQ (x, Qnil) | 388 | #define lisp_h_NILP(x) BASE_EQ (x, Qnil) |
| 388 | #define lisp_h_SET_SYMBOL_VAL(sym, v) \ | ||
| 389 | (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), \ | ||
| 390 | (sym)->u.s.val.value = (v)) | ||
| 391 | #define lisp_h_SYMBOL_CONSTANT_P(sym) \ | 389 | #define lisp_h_SYMBOL_CONSTANT_P(sym) \ |
| 392 | (XSYMBOL (sym)->u.s.trapped_write == SYMBOL_NOWRITE) | 390 | (XSYMBOL (sym)->u.s.trapped_write == SYMBOL_NOWRITE) |
| 393 | #define lisp_h_SYMBOL_TRAPPED_WRITE_P(sym) (XSYMBOL (sym)->u.s.trapped_write) | 391 | #define lisp_h_SYMBOL_TRAPPED_WRITE_P(sym) (XSYMBOL (sym)->u.s.trapped_write) |
| 394 | #define lisp_h_SYMBOL_VAL(sym) \ | ||
| 395 | (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), (sym)->u.s.val.value) | ||
| 396 | #define lisp_h_SYMBOL_WITH_POS_P(x) PSEUDOVECTORP (x, PVEC_SYMBOL_WITH_POS) | 392 | #define lisp_h_SYMBOL_WITH_POS_P(x) PSEUDOVECTORP (x, PVEC_SYMBOL_WITH_POS) |
| 397 | #define lisp_h_BARE_SYMBOL_P(x) TAGGEDP (x, Lisp_Symbol) | 393 | #define lisp_h_BARE_SYMBOL_P(x) TAGGEDP (x, Lisp_Symbol) |
| 398 | #define lisp_h_TAGGEDP(a, tag) \ | 394 | #define lisp_h_TAGGEDP(a, tag) \ |
| @@ -402,8 +398,6 @@ typedef EMACS_INT Lisp_Word; | |||
| 402 | #define lisp_h_VECTORLIKEP(x) TAGGEDP (x, Lisp_Vectorlike) | 398 | #define lisp_h_VECTORLIKEP(x) TAGGEDP (x, Lisp_Vectorlike) |
| 403 | #define lisp_h_XCAR(c) XCONS (c)->u.s.car | 399 | #define lisp_h_XCAR(c) XCONS (c)->u.s.car |
| 404 | #define lisp_h_XCDR(c) XCONS (c)->u.s.u.cdr | 400 | #define lisp_h_XCDR(c) XCONS (c)->u.s.u.cdr |
| 405 | #define lisp_h_XCONS(a) \ | ||
| 406 | (eassert (CONSP (a)), XUNTAG (a, Lisp_Cons, struct Lisp_Cons)) | ||
| 407 | #define lisp_h_XHASH(a) XUFIXNUM_RAW (a) | 401 | #define lisp_h_XHASH(a) XUFIXNUM_RAW (a) |
| 408 | #if USE_LSB_TAG | 402 | #if USE_LSB_TAG |
| 409 | # define lisp_h_make_fixnum_wrap(n) \ | 403 | # define lisp_h_make_fixnum_wrap(n) \ |
| @@ -448,15 +442,12 @@ typedef EMACS_INT Lisp_Word; | |||
| 448 | # define FLOATP(x) lisp_h_FLOATP (x) | 442 | # define FLOATP(x) lisp_h_FLOATP (x) |
| 449 | # define FIXNUMP(x) lisp_h_FIXNUMP (x) | 443 | # define FIXNUMP(x) lisp_h_FIXNUMP (x) |
| 450 | # define NILP(x) lisp_h_NILP (x) | 444 | # define NILP(x) lisp_h_NILP (x) |
| 451 | # define SET_SYMBOL_VAL(sym, v) lisp_h_SET_SYMBOL_VAL (sym, v) | ||
| 452 | # define SYMBOL_CONSTANT_P(sym) lisp_h_SYMBOL_CONSTANT_P (sym) | 445 | # define SYMBOL_CONSTANT_P(sym) lisp_h_SYMBOL_CONSTANT_P (sym) |
| 453 | # define SYMBOL_TRAPPED_WRITE_P(sym) lisp_h_SYMBOL_TRAPPED_WRITE_P (sym) | 446 | # define SYMBOL_TRAPPED_WRITE_P(sym) lisp_h_SYMBOL_TRAPPED_WRITE_P (sym) |
| 454 | # define SYMBOL_VAL(sym) lisp_h_SYMBOL_VAL (sym) | ||
| 455 | # define TAGGEDP(a, tag) lisp_h_TAGGEDP (a, tag) | 447 | # define TAGGEDP(a, tag) lisp_h_TAGGEDP (a, tag) |
| 456 | # define VECTORLIKEP(x) lisp_h_VECTORLIKEP (x) | 448 | # define VECTORLIKEP(x) lisp_h_VECTORLIKEP (x) |
| 457 | # define XCAR(c) lisp_h_XCAR (c) | 449 | # define XCAR(c) lisp_h_XCAR (c) |
| 458 | # define XCDR(c) lisp_h_XCDR (c) | 450 | # define XCDR(c) lisp_h_XCDR (c) |
| 459 | # define XCONS(a) lisp_h_XCONS (a) | ||
| 460 | # define XHASH(a) lisp_h_XHASH (a) | 451 | # define XHASH(a) lisp_h_XHASH (a) |
| 461 | # if USE_LSB_TAG | 452 | # if USE_LSB_TAG |
| 462 | # define make_fixnum(n) lisp_h_make_fixnum (n) | 453 | # define make_fixnum(n) lisp_h_make_fixnum (n) |
| @@ -1478,9 +1469,10 @@ CHECK_CONS (Lisp_Object x) | |||
| 1478 | } | 1469 | } |
| 1479 | 1470 | ||
| 1480 | INLINE struct Lisp_Cons * | 1471 | INLINE struct Lisp_Cons * |
| 1481 | (XCONS) (Lisp_Object a) | 1472 | XCONS (Lisp_Object a) |
| 1482 | { | 1473 | { |
| 1483 | return lisp_h_XCONS (a); | 1474 | eassert (CONSP (a)); |
| 1475 | return XUNTAG (a, Lisp_Cons, struct Lisp_Cons); | ||
| 1484 | } | 1476 | } |
| 1485 | 1477 | ||
| 1486 | /* Take the car or cdr of something known to be a cons cell. */ | 1478 | /* Take the car or cdr of something known to be a cons cell. */ |
| @@ -2265,9 +2257,10 @@ typedef jmp_buf sys_jmp_buf; | |||
| 2265 | /* Value is name of symbol. */ | 2257 | /* Value is name of symbol. */ |
| 2266 | 2258 | ||
| 2267 | INLINE Lisp_Object | 2259 | INLINE Lisp_Object |
| 2268 | (SYMBOL_VAL) (struct Lisp_Symbol *sym) | 2260 | SYMBOL_VAL (struct Lisp_Symbol *sym) |
| 2269 | { | 2261 | { |
| 2270 | return lisp_h_SYMBOL_VAL (sym); | 2262 | eassert (sym->u.s.redirect == SYMBOL_PLAINVAL); |
| 2263 | return sym->u.s.val.value; | ||
| 2271 | } | 2264 | } |
| 2272 | 2265 | ||
| 2273 | INLINE struct Lisp_Symbol * | 2266 | INLINE struct Lisp_Symbol * |
| @@ -2290,9 +2283,10 @@ SYMBOL_FWD (struct Lisp_Symbol *sym) | |||
| 2290 | } | 2283 | } |
| 2291 | 2284 | ||
| 2292 | INLINE void | 2285 | INLINE void |
| 2293 | (SET_SYMBOL_VAL) (struct Lisp_Symbol *sym, Lisp_Object v) | 2286 | SET_SYMBOL_VAL (struct Lisp_Symbol *sym, Lisp_Object v) |
| 2294 | { | 2287 | { |
| 2295 | lisp_h_SET_SYMBOL_VAL (sym, v); | 2288 | eassert (sym->u.s.redirect == SYMBOL_PLAINVAL); |
| 2289 | sym->u.s.val.value = v; | ||
| 2296 | } | 2290 | } |
| 2297 | 2291 | ||
| 2298 | INLINE void | 2292 | INLINE void |