From: Paul Eggert Date: Sat, 17 Aug 2024 02:02:55 +0000 (-0700) Subject: Tune volatile in read_char X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=79d8ebf2dbcdf013594982b13c5e9381d2ad63fa;p=emacs.git Tune volatile in read_char * src/keyboard.c (read_char): Optimize access to a local volatile. (cherry picked from commit 8c81818673ae9ff788c6e65fb90984f327b27964) --- diff --git a/src/keyboard.c b/src/keyboard.c index 6e088372fcf..6438e9cacb4 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2517,7 +2517,7 @@ read_char (int commandflag, Lisp_Object map, Lisp_Object prev_event, bool *used_mouse_menu, struct timespec *end_time) { - Lisp_Object volatile c; + Lisp_Object c; sys_jmp_buf local_getcjmp; sys_jmp_buf save_jump; Lisp_Object tem, save; @@ -2752,8 +2752,10 @@ read_char (int commandflag, Lisp_Object map, it *must not* be in effect when we call redisplay. */ specpdl_ref jmpcount = SPECPDL_INDEX (); + Lisp_Object volatile c_volatile; if (sys_setjmp (local_getcjmp)) { + c = c_volatile; /* Handle quits while reading the keyboard. */ /* We must have saved the outer value of getcjmp here, so restore it now. */ @@ -2798,6 +2800,13 @@ read_char (int commandflag, Lisp_Object map, goto non_reread; } + c_volatile = c; +#if GCC_LINT && __GNUC__ && !__clang__ + /* This useless assignment pacifies GCC 14.2.1 x86-64 + . */ + c = c_volatile; +#endif + /* Start idle timers if no time limit is supplied. We don't do it if a time limit is supplied to avoid an infinite recursion in the situation where an idle timer calls `sit-for'. */ @@ -2959,6 +2968,8 @@ read_char (int commandflag, Lisp_Object map, } reread = true; } + + c_volatile = c; } /* Read something from current KBOARD's side queue, if possible. */ @@ -2970,6 +2981,7 @@ read_char (int commandflag, Lisp_Object map, if (!CONSP (KVAR (current_kboard, kbd_queue))) emacs_abort (); c = XCAR (KVAR (current_kboard, kbd_queue)); + c_volatile = c; kset_kbd_queue (current_kboard, XCDR (KVAR (current_kboard, kbd_queue))); if (NILP (KVAR (current_kboard, kbd_queue))) @@ -3025,6 +3037,8 @@ read_char (int commandflag, Lisp_Object map, c = XCDR (c); recorded = true; } + + c_volatile = c; } non_reread: @@ -3108,7 +3122,7 @@ read_char (int commandflag, Lisp_Object map, d = Faref (KVAR (current_kboard, Vkeyboard_translate_table), c); /* nil in keyboard-translate-table means no translation. */ if (!NILP (d)) - c = d; + c_volatile = c = d; } } @@ -3148,6 +3162,7 @@ read_char (int commandflag, Lisp_Object map, Vunread_command_events = Fcons (c, Vunread_command_events); } c = posn; + c_volatile = c; } } @@ -3273,6 +3288,7 @@ read_char (int commandflag, Lisp_Object map, } /* It returned one event or more. */ c = XCAR (tem); + c_volatile = c; Vunread_post_input_method_events = nconc2 (XCDR (tem), Vunread_post_input_method_events); } @@ -3347,6 +3363,7 @@ read_char (int commandflag, Lisp_Object map, do { c = read_char (0, Qnil, Qnil, 0, NULL); + c_volatile = c; if (EVENT_HAS_PARAMETERS (c) && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_click)) XSETCAR (help_form_saved_window_configs, Qnil); @@ -3360,7 +3377,7 @@ read_char (int commandflag, Lisp_Object map, { cancel_echoing (); do - c = read_char (0, Qnil, Qnil, 0, NULL); + c_volatile = c = read_char (0, Qnil, Qnil, 0, NULL); while (BUFFERP (c)); } }