diff options
| author | Paul Eggert | 2018-06-09 18:59:25 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-06-09 19:02:09 -0700 |
| commit | efa750e68466fb1bab03028701350a745e0504b6 (patch) | |
| tree | 6e179e82b4033c0aa43882ce31973032f22706b3 /src | |
| parent | cace203da108da4d281a99953a6fc71a18cde029 (diff) | |
| download | emacs-efa750e68466fb1bab03028701350a745e0504b6.tar.gz emacs-efa750e68466fb1bab03028701350a745e0504b6.zip | |
Simplify read_key_sequence
* src/keyboard.c (READ_KEY_ELTS): New constant.
(keyremap_step, read_key_sequence): Omit BUFSIZE arg, since it's
always READ_KEY_ELTS. All callers changed.
(grow_bool_vector): Remove; no longer needed.
(read_key_sequence): Use a bool array instead of a Lisp bool
vector, since it's small and this puts less pressure on the GC.
Diffstat (limited to 'src')
| -rw-r--r-- | src/keyboard.c | 98 |
1 files changed, 30 insertions, 68 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index c92684d3a3e..e6b5cf79983 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -1251,7 +1251,8 @@ some_mouse_moved (void) | |||
| 1251 | /* This is the actual command reading loop, | 1251 | /* This is the actual command reading loop, |
| 1252 | sans error-handling encapsulation. */ | 1252 | sans error-handling encapsulation. */ |
| 1253 | 1253 | ||
| 1254 | static int read_key_sequence (Lisp_Object *, int, Lisp_Object, | 1254 | enum { READ_KEY_ELTS = 30 }; |
| 1255 | static int read_key_sequence (Lisp_Object *, Lisp_Object, | ||
| 1255 | bool, bool, bool, bool); | 1256 | bool, bool, bool, bool); |
| 1256 | static void adjust_point_for_property (ptrdiff_t, bool); | 1257 | static void adjust_point_for_property (ptrdiff_t, bool); |
| 1257 | 1258 | ||
| @@ -1299,11 +1300,9 @@ command_loop_1 (void) | |||
| 1299 | if (!CONSP (last_command_event)) | 1300 | if (!CONSP (last_command_event)) |
| 1300 | kset_last_repeatable_command (current_kboard, Vreal_this_command); | 1301 | kset_last_repeatable_command (current_kboard, Vreal_this_command); |
| 1301 | 1302 | ||
| 1302 | while (1) | 1303 | while (true) |
| 1303 | { | 1304 | { |
| 1304 | Lisp_Object cmd; | 1305 | Lisp_Object cmd; |
| 1305 | Lisp_Object keybuf[30]; | ||
| 1306 | int i; | ||
| 1307 | 1306 | ||
| 1308 | if (! FRAME_LIVE_P (XFRAME (selected_frame))) | 1307 | if (! FRAME_LIVE_P (XFRAME (selected_frame))) |
| 1309 | Fkill_emacs (Qnil); | 1308 | Fkill_emacs (Qnil); |
| @@ -1367,8 +1366,8 @@ command_loop_1 (void) | |||
| 1367 | 1366 | ||
| 1368 | /* Read next key sequence; i gets its length. */ | 1367 | /* Read next key sequence; i gets its length. */ |
| 1369 | raw_keybuf_count = 0; | 1368 | raw_keybuf_count = 0; |
| 1370 | i = read_key_sequence (keybuf, ARRAYELTS (keybuf), | 1369 | Lisp_Object keybuf[READ_KEY_ELTS]; |
| 1371 | Qnil, 0, 1, 1, 0); | 1370 | int i = read_key_sequence (keybuf, Qnil, false, true, true, false); |
| 1372 | 1371 | ||
| 1373 | /* A filter may have run while we were reading the input. */ | 1372 | /* A filter may have run while we were reading the input. */ |
| 1374 | if (! FRAME_LIVE_P (XFRAME (selected_frame))) | 1373 | if (! FRAME_LIVE_P (XFRAME (selected_frame))) |
| @@ -1604,16 +1603,14 @@ command_loop_1 (void) | |||
| 1604 | Lisp_Object | 1603 | Lisp_Object |
| 1605 | read_menu_command (void) | 1604 | read_menu_command (void) |
| 1606 | { | 1605 | { |
| 1607 | Lisp_Object keybuf[30]; | ||
| 1608 | ptrdiff_t count = SPECPDL_INDEX (); | 1606 | ptrdiff_t count = SPECPDL_INDEX (); |
| 1609 | int i; | ||
| 1610 | 1607 | ||
| 1611 | /* We don't want to echo the keystrokes while navigating the | 1608 | /* We don't want to echo the keystrokes while navigating the |
| 1612 | menus. */ | 1609 | menus. */ |
| 1613 | specbind (Qecho_keystrokes, make_number (0)); | 1610 | specbind (Qecho_keystrokes, make_number (0)); |
| 1614 | 1611 | ||
| 1615 | i = read_key_sequence (keybuf, ARRAYELTS (keybuf), | 1612 | Lisp_Object keybuf[READ_KEY_ELTS]; |
| 1616 | Qnil, 0, 1, 1, 1); | 1613 | int i = read_key_sequence (keybuf, Qnil, false, true, true, true); |
| 1617 | 1614 | ||
| 1618 | unbind_to (count, Qnil); | 1615 | unbind_to (count, Qnil); |
| 1619 | 1616 | ||
| @@ -8778,8 +8775,7 @@ access_keymap_keyremap (Lisp_Object map, Lisp_Object key, Lisp_Object prompt, | |||
| 8778 | 8775 | ||
| 8779 | /* Do one step of the key remapping used for function-key-map and | 8776 | /* Do one step of the key remapping used for function-key-map and |
| 8780 | key-translation-map: | 8777 | key-translation-map: |
| 8781 | KEYBUF is the buffer holding the input events. | 8778 | KEYBUF is the READ_KEY_ELTS-size buffer holding the input events. |
| 8782 | BUFSIZE is its maximum size. | ||
| 8783 | FKEY is a pointer to the keyremap structure to use. | 8779 | FKEY is a pointer to the keyremap structure to use. |
| 8784 | INPUT is the index of the last element in KEYBUF. | 8780 | INPUT is the index of the last element in KEYBUF. |
| 8785 | DOIT if true says that the remapping can actually take place. | 8781 | DOIT if true says that the remapping can actually take place. |
| @@ -8789,7 +8785,7 @@ access_keymap_keyremap (Lisp_Object map, Lisp_Object key, Lisp_Object prompt, | |||
| 8789 | Return true if the remapping actually took place. */ | 8785 | Return true if the remapping actually took place. */ |
| 8790 | 8786 | ||
| 8791 | static bool | 8787 | static bool |
| 8792 | keyremap_step (Lisp_Object *keybuf, int bufsize, volatile keyremap *fkey, | 8788 | keyremap_step (Lisp_Object *keybuf, volatile keyremap *fkey, |
| 8793 | int input, bool doit, int *diff, Lisp_Object prompt) | 8789 | int input, bool doit, int *diff, Lisp_Object prompt) |
| 8794 | { | 8790 | { |
| 8795 | Lisp_Object next, key; | 8791 | Lisp_Object next, key; |
| @@ -8811,7 +8807,7 @@ keyremap_step (Lisp_Object *keybuf, int bufsize, volatile keyremap *fkey, | |||
| 8811 | 8807 | ||
| 8812 | *diff = len - (fkey->end - fkey->start); | 8808 | *diff = len - (fkey->end - fkey->start); |
| 8813 | 8809 | ||
| 8814 | if (bufsize - input <= *diff) | 8810 | if (READ_KEY_ELTS - input <= *diff) |
| 8815 | error ("Key sequence too long"); | 8811 | error ("Key sequence too long"); |
| 8816 | 8812 | ||
| 8817 | /* Shift the keys that follow fkey->end. */ | 8813 | /* Shift the keys that follow fkey->end. */ |
| @@ -8858,33 +8854,8 @@ void init_raw_keybuf_count (void) | |||
| 8858 | raw_keybuf_count = 0; | 8854 | raw_keybuf_count = 0; |
| 8859 | } | 8855 | } |
| 8860 | 8856 | ||
| 8861 | /* Grow a vector to fit. | ||
| 8862 | |||
| 8863 | On entry, *VECTOR is nil or a bool vector. Upon return, *VECTOR | ||
| 8864 | contains a bool vector of size at least NEEDED_LENGTH, with any new | ||
| 8865 | values to false. Return the new value of *VECTOR. */ | ||
| 8866 | static Lisp_Object | ||
| 8867 | grow_bool_vector (Lisp_Object *vector, int needed_length) | ||
| 8868 | { | ||
| 8869 | EMACS_INT old_length = NILP (*vector) ? 0 : bool_vector_size (*vector); | ||
| 8870 | if (NILP (*vector) || old_length < needed_length) | ||
| 8871 | { | ||
| 8872 | EMACS_INT new_length = old_length ? old_length : 64; | ||
| 8873 | while (new_length < needed_length) | ||
| 8874 | new_length *= 2; | ||
| 8875 | Lisp_Object new_vector = | ||
| 8876 | Fmake_bool_vector (make_number (needed_length), Qnil); | ||
| 8877 | if (old_length) | ||
| 8878 | memcpy (bool_vector_data (new_vector), | ||
| 8879 | bool_vector_data (*vector), | ||
| 8880 | bool_vector_bytes (old_length)); | ||
| 8881 | *vector = new_vector; | ||
| 8882 | } | ||
| 8883 | return *vector; | ||
| 8884 | } | ||
| 8885 | |||
| 8886 | /* Read a sequence of keys that ends with a non prefix character, | 8857 | /* Read a sequence of keys that ends with a non prefix character, |
| 8887 | storing it in KEYBUF, a buffer of size BUFSIZE. | 8858 | storing it in KEYBUF, a buffer of size READ_KEY_ELTS. |
| 8888 | Prompt with PROMPT. | 8859 | Prompt with PROMPT. |
| 8889 | Return the length of the key sequence stored. | 8860 | Return the length of the key sequence stored. |
| 8890 | Return -1 if the user rejected a command menu. | 8861 | Return -1 if the user rejected a command menu. |
| @@ -8924,7 +8895,7 @@ grow_bool_vector (Lisp_Object *vector, int needed_length) | |||
| 8924 | from the selected window's buffer. */ | 8895 | from the selected window's buffer. */ |
| 8925 | 8896 | ||
| 8926 | static int | 8897 | static int |
| 8927 | read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | 8898 | read_key_sequence (Lisp_Object *keybuf, Lisp_Object prompt, |
| 8928 | bool dont_downcase_last, bool can_return_switch_frame, | 8899 | bool dont_downcase_last, bool can_return_switch_frame, |
| 8929 | bool fix_current_buffer, bool prevent_redisplay) | 8900 | bool fix_current_buffer, bool prevent_redisplay) |
| 8930 | { | 8901 | { |
| @@ -8959,10 +8930,8 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 8959 | reading characters from the keyboard. */ | 8930 | reading characters from the keyboard. */ |
| 8960 | int mock_input = 0; | 8931 | int mock_input = 0; |
| 8961 | 8932 | ||
| 8962 | /* This bool vector remembers whether each event in the mocked input | 8933 | /* Whether each event in the mocked input came from a mouse menu. */ |
| 8963 | came from a mouse menu. We ordinarily leave it nil and create it | 8934 | bool used_mouse_menu_history[READ_KEY_ELTS] = {0}; |
| 8964 | the first time we remember a mouse event. */ | ||
| 8965 | Lisp_Object used_mouse_menu_history = Qnil; | ||
| 8966 | 8935 | ||
| 8967 | /* Distinguish first time through from replay with mock_input == 0. */ | 8936 | /* Distinguish first time through from replay with mock_input == 0. */ |
| 8968 | bool is_replay = false; | 8937 | bool is_replay = false; |
| @@ -9057,7 +9026,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9057 | replay_sequence: | 9026 | replay_sequence: |
| 9058 | 9027 | ||
| 9059 | starting_buffer = current_buffer; | 9028 | starting_buffer = current_buffer; |
| 9060 | first_unbound = bufsize + 1; | 9029 | first_unbound = READ_KEY_ELTS + 1; |
| 9061 | Lisp_Object first_event = mock_input > 0 ? keybuf[0] : Qnil; | 9030 | Lisp_Object first_event = mock_input > 0 ? keybuf[0] : Qnil; |
| 9062 | Lisp_Object second_event = mock_input > 1 ? keybuf[1] : Qnil; | 9031 | Lisp_Object second_event = mock_input > 1 ? keybuf[1] : Qnil; |
| 9063 | 9032 | ||
| @@ -9139,7 +9108,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9139 | goto replay_sequence; | 9108 | goto replay_sequence; |
| 9140 | } | 9109 | } |
| 9141 | 9110 | ||
| 9142 | if (t >= bufsize) | 9111 | if (t >= READ_KEY_ELTS) |
| 9143 | error ("Key sequence too long"); | 9112 | error ("Key sequence too long"); |
| 9144 | 9113 | ||
| 9145 | if (INTERACTIVE) | 9114 | if (INTERACTIVE) |
| @@ -9170,9 +9139,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9170 | current_kboard->immediate_echo = false; | 9139 | current_kboard->immediate_echo = false; |
| 9171 | echo_now (); | 9140 | echo_now (); |
| 9172 | } | 9141 | } |
| 9173 | used_mouse_menu = !NILP (used_mouse_menu_history) && | 9142 | used_mouse_menu = used_mouse_menu_history[t]; |
| 9174 | t < bool_vector_size (used_mouse_menu_history) && | ||
| 9175 | bool_vector_bitref (used_mouse_menu_history, t); | ||
| 9176 | } | 9143 | } |
| 9177 | 9144 | ||
| 9178 | /* If not, we should actually read a character. */ | 9145 | /* If not, we should actually read a character. */ |
| @@ -9186,10 +9153,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9186 | key = read_char (prevent_redisplay ? -2 : NILP (prompt), | 9153 | key = read_char (prevent_redisplay ? -2 : NILP (prompt), |
| 9187 | current_binding, last_nonmenu_event, | 9154 | current_binding, last_nonmenu_event, |
| 9188 | &used_mouse_menu, NULL); | 9155 | &used_mouse_menu, NULL); |
| 9189 | if (used_mouse_menu || !NILP (used_mouse_menu_history)) | 9156 | used_mouse_menu_history[t] = used_mouse_menu; |
| 9190 | bool_vector_set ( | ||
| 9191 | grow_bool_vector (&used_mouse_menu_history, t + 1), | ||
| 9192 | t, used_mouse_menu); | ||
| 9193 | if ((INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */ | 9157 | if ((INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */ |
| 9194 | /* When switching to a new tty (with a new keyboard), | 9158 | /* When switching to a new tty (with a new keyboard), |
| 9195 | read_char returns the new buffer, rather than -2 | 9159 | read_char returns the new buffer, rather than -2 |
| @@ -9417,7 +9381,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9417 | && (NILP (fake_prefixed_keys) | 9381 | && (NILP (fake_prefixed_keys) |
| 9418 | || NILP (Fmemq (key, fake_prefixed_keys)))) | 9382 | || NILP (Fmemq (key, fake_prefixed_keys)))) |
| 9419 | { | 9383 | { |
| 9420 | if (bufsize - t <= 1) | 9384 | if (READ_KEY_ELTS - t <= 1) |
| 9421 | error ("Key sequence too long"); | 9385 | error ("Key sequence too long"); |
| 9422 | 9386 | ||
| 9423 | keybuf[t] = posn; | 9387 | keybuf[t] = posn; |
| @@ -9443,7 +9407,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9443 | insert the dummy prefix event `menu-bar'. */ | 9407 | insert the dummy prefix event `menu-bar'. */ |
| 9444 | if (EQ (posn, Qmenu_bar) || EQ (posn, Qtool_bar)) | 9408 | if (EQ (posn, Qmenu_bar) || EQ (posn, Qtool_bar)) |
| 9445 | { | 9409 | { |
| 9446 | if (bufsize - t <= 1) | 9410 | if (READ_KEY_ELTS - t <= 1) |
| 9447 | error ("Key sequence too long"); | 9411 | error ("Key sequence too long"); |
| 9448 | keybuf[t] = posn; | 9412 | keybuf[t] = posn; |
| 9449 | keybuf[t + 1] = key; | 9413 | keybuf[t + 1] = key; |
| @@ -9646,8 +9610,8 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9646 | bool done; | 9610 | bool done; |
| 9647 | int diff; | 9611 | int diff; |
| 9648 | 9612 | ||
| 9649 | done = keyremap_step (keybuf, bufsize, &indec, max (t, mock_input), | 9613 | done = keyremap_step (keybuf, &indec, max (t, mock_input), |
| 9650 | 1, &diff, prompt); | 9614 | true, &diff, prompt); |
| 9651 | if (done) | 9615 | if (done) |
| 9652 | { | 9616 | { |
| 9653 | mock_input = diff + max (t, mock_input); | 9617 | mock_input = diff + max (t, mock_input); |
| @@ -9677,13 +9641,13 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9677 | bool done; | 9641 | bool done; |
| 9678 | int diff; | 9642 | int diff; |
| 9679 | 9643 | ||
| 9680 | done = keyremap_step (keybuf, bufsize, &fkey, | 9644 | done = keyremap_step (keybuf, &fkey, |
| 9681 | max (t, mock_input), | 9645 | max (t, mock_input), |
| 9682 | /* If there's a binding (i.e. | 9646 | /* If there's a binding (i.e. |
| 9683 | first_binding >= nmaps) we don't want | 9647 | first_binding >= nmaps) we don't want |
| 9684 | to apply this function-key-mapping. */ | 9648 | to apply this function-key-mapping. */ |
| 9685 | fkey.end + 1 == t | 9649 | (fkey.end + 1 == t |
| 9686 | && (test_undefined (current_binding)), | 9650 | && test_undefined (current_binding)), |
| 9687 | &diff, prompt); | 9651 | &diff, prompt); |
| 9688 | if (done) | 9652 | if (done) |
| 9689 | { | 9653 | { |
| @@ -9703,8 +9667,8 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9703 | bool done; | 9667 | bool done; |
| 9704 | int diff; | 9668 | int diff; |
| 9705 | 9669 | ||
| 9706 | done = keyremap_step (keybuf, bufsize, &keytran, max (t, mock_input), | 9670 | done = keyremap_step (keybuf, &keytran, max (t, mock_input), |
| 9707 | 1, &diff, prompt); | 9671 | true, &diff, prompt); |
| 9708 | if (done) | 9672 | if (done) |
| 9709 | { | 9673 | { |
| 9710 | mock_input = diff + max (t, mock_input); | 9674 | mock_input = diff + max (t, mock_input); |
| @@ -9857,8 +9821,6 @@ read_key_sequence_vs (Lisp_Object prompt, Lisp_Object continue_echo, | |||
| 9857 | Lisp_Object can_return_switch_frame, | 9821 | Lisp_Object can_return_switch_frame, |
| 9858 | Lisp_Object cmd_loop, bool allow_string) | 9822 | Lisp_Object cmd_loop, bool allow_string) |
| 9859 | { | 9823 | { |
| 9860 | Lisp_Object keybuf[30]; | ||
| 9861 | int i; | ||
| 9862 | ptrdiff_t count = SPECPDL_INDEX (); | 9824 | ptrdiff_t count = SPECPDL_INDEX (); |
| 9863 | 9825 | ||
| 9864 | if (!NILP (prompt)) | 9826 | if (!NILP (prompt)) |
| @@ -9882,9 +9844,9 @@ read_key_sequence_vs (Lisp_Object prompt, Lisp_Object continue_echo, | |||
| 9882 | #endif | 9844 | #endif |
| 9883 | 9845 | ||
| 9884 | raw_keybuf_count = 0; | 9846 | raw_keybuf_count = 0; |
| 9885 | i = read_key_sequence (keybuf, ARRAYELTS (keybuf), | 9847 | Lisp_Object keybuf[READ_KEY_ELTS]; |
| 9886 | prompt, ! NILP (dont_downcase_last), | 9848 | int i = read_key_sequence (keybuf, prompt, ! NILP (dont_downcase_last), |
| 9887 | ! NILP (can_return_switch_frame), 0, 0); | 9849 | ! NILP (can_return_switch_frame), false, false); |
| 9888 | 9850 | ||
| 9889 | #if 0 /* The following is fine for code reading a key sequence and | 9851 | #if 0 /* The following is fine for code reading a key sequence and |
| 9890 | then proceeding with a lengthy computation, but it's not good | 9852 | then proceeding with a lengthy computation, but it's not good |