diff options
| author | Ihor Radchenko | 2023-12-15 11:47:45 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2023-12-30 10:03:46 +0200 |
| commit | aa0037aaf7c2cd7052925fdeca73c77c91254de1 (patch) | |
| tree | 0d97c7c0d6d31149404f9d3e687bd1de4abfeb81 /src | |
| parent | 784acce8425fb3143719d34be1e39be499564dfb (diff) | |
| download | emacs-aa0037aaf7c2cd7052925fdeca73c77c91254de1.tar.gz emacs-aa0037aaf7c2cd7052925fdeca73c77c91254de1.zip | |
Improve performance let-binding `case-fold-search' (bug#66117)
* src/buffer.h: Remove case_fold_search_ buffer object slot.
* src/buffer.c (bset_case_fold_search): Remove - no longer needed.
(init_buffer_once): Remove removed buffer slot init.
(syms_of_buffer): Use DEFVAR_LISP to define `case-fold-search' and
declare it buffer-local.
* src/minibuf.c (syms_of_minibuf): Remove DEFSYM call for
`case-fold-search' symbol. It now lives in `syms_of_buffer'.
* src/editfns.c (Fcompare_buffer_substrings):
(Fchar_equal):
* src/search.c (looking_at_1):
(string_match_1):
(search_command):
(Fre__describe_compiled): Adjust C queries to `case-fold-search' value
to use C globals instead of BVAR macro.
* doc/lispref/internals.texi (Buffer Internals): Do not list
`case_fold_search' slot.
See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66117#259
When used as buffer slot, let-binding `case-fold-search' would scale
with the number of live buffers and can be slow. This change makes
let-binding much faster at the cost of slightly slower `set-buffer'.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.c | 17 | ||||
| -rw-r--r-- | src/buffer.h | 1 | ||||
| -rw-r--r-- | src/editfns.c | 4 | ||||
| -rw-r--r-- | src/minibuf.c | 1 | ||||
| -rw-r--r-- | src/search.c | 10 |
5 files changed, 13 insertions, 20 deletions
diff --git a/src/buffer.c b/src/buffer.c index d08ea44d797..637830704e6 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -210,11 +210,6 @@ bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val) | |||
| 210 | b->buffer_file_coding_system_ = val; | 210 | b->buffer_file_coding_system_ = val; |
| 211 | } | 211 | } |
| 212 | static void | 212 | static void |
| 213 | bset_case_fold_search (struct buffer *b, Lisp_Object val) | ||
| 214 | { | ||
| 215 | b->case_fold_search_ = val; | ||
| 216 | } | ||
| 217 | static void | ||
| 218 | bset_ctl_arrow (struct buffer *b, Lisp_Object val) | 213 | bset_ctl_arrow (struct buffer *b, Lisp_Object val) |
| 219 | { | 214 | { |
| 220 | b->ctl_arrow_ = val; | 215 | b->ctl_arrow_ = val; |
| @@ -4692,7 +4687,6 @@ init_buffer_once (void) | |||
| 4692 | XSETFASTINT (BVAR (&buffer_local_flags, mode_line_format), idx); ++idx; | 4687 | XSETFASTINT (BVAR (&buffer_local_flags, mode_line_format), idx); ++idx; |
| 4693 | XSETFASTINT (BVAR (&buffer_local_flags, abbrev_mode), idx); ++idx; | 4688 | XSETFASTINT (BVAR (&buffer_local_flags, abbrev_mode), idx); ++idx; |
| 4694 | XSETFASTINT (BVAR (&buffer_local_flags, overwrite_mode), idx); ++idx; | 4689 | XSETFASTINT (BVAR (&buffer_local_flags, overwrite_mode), idx); ++idx; |
| 4695 | XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx; | ||
| 4696 | XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx; | 4690 | XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx; |
| 4697 | XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx; | 4691 | XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx; |
| 4698 | XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx; | 4692 | XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx; |
| @@ -4785,7 +4779,6 @@ init_buffer_once (void) | |||
| 4785 | bset_tab_line_format (&buffer_defaults, Qnil); | 4779 | bset_tab_line_format (&buffer_defaults, Qnil); |
| 4786 | bset_abbrev_mode (&buffer_defaults, Qnil); | 4780 | bset_abbrev_mode (&buffer_defaults, Qnil); |
| 4787 | bset_overwrite_mode (&buffer_defaults, Qnil); | 4781 | bset_overwrite_mode (&buffer_defaults, Qnil); |
| 4788 | bset_case_fold_search (&buffer_defaults, Qt); | ||
| 4789 | bset_auto_fill_function (&buffer_defaults, Qnil); | 4782 | bset_auto_fill_function (&buffer_defaults, Qnil); |
| 4790 | bset_selective_display (&buffer_defaults, Qnil); | 4783 | bset_selective_display (&buffer_defaults, Qnil); |
| 4791 | bset_selective_display_ellipses (&buffer_defaults, Qt); | 4784 | bset_selective_display_ellipses (&buffer_defaults, Qt); |
| @@ -5215,10 +5208,6 @@ Format with `format-mode-line' to produce a string value. */); | |||
| 5215 | doc: /* Non-nil if Abbrev mode is enabled. | 5208 | doc: /* Non-nil if Abbrev mode is enabled. |
| 5216 | Use the command `abbrev-mode' to change this variable. */); | 5209 | Use the command `abbrev-mode' to change this variable. */); |
| 5217 | 5210 | ||
| 5218 | DEFVAR_PER_BUFFER ("case-fold-search", &BVAR (current_buffer, case_fold_search), | ||
| 5219 | Qnil, | ||
| 5220 | doc: /* Non-nil if searches and matches should ignore case. */); | ||
| 5221 | |||
| 5222 | DEFVAR_PER_BUFFER ("fill-column", &BVAR (current_buffer, fill_column), | 5211 | DEFVAR_PER_BUFFER ("fill-column", &BVAR (current_buffer, fill_column), |
| 5223 | Qintegerp, | 5212 | Qintegerp, |
| 5224 | doc: /* Column beyond which automatic line-wrapping should happen. | 5213 | doc: /* Column beyond which automatic line-wrapping should happen. |
| @@ -5951,6 +5940,12 @@ If `delete-auto-save-files' is nil, any autosave deletion is inhibited. */); | |||
| 5951 | This is the default. If nil, auto-save file deletion is inhibited. */); | 5940 | This is the default. If nil, auto-save file deletion is inhibited. */); |
| 5952 | delete_auto_save_files = 1; | 5941 | delete_auto_save_files = 1; |
| 5953 | 5942 | ||
| 5943 | DEFVAR_LISP ("case-fold-search", Vcase_fold_search, | ||
| 5944 | doc: /* Non-nil if searches and matches should ignore case. */); | ||
| 5945 | Vcase_fold_search = Qt; | ||
| 5946 | DEFSYM (Qcase_fold_search, "case-fold-search"); | ||
| 5947 | Fmake_variable_buffer_local (Qcase_fold_search); | ||
| 5948 | |||
| 5954 | DEFVAR_LISP ("clone-indirect-buffer-hook", Vclone_indirect_buffer_hook, | 5949 | DEFVAR_LISP ("clone-indirect-buffer-hook", Vclone_indirect_buffer_hook, |
| 5955 | doc: /* Normal hook to run in the new buffer at the end of `make-indirect-buffer'. | 5950 | doc: /* Normal hook to run in the new buffer at the end of `make-indirect-buffer'. |
| 5956 | 5951 | ||
diff --git a/src/buffer.h b/src/buffer.h index b2bd15657dc..399c6585158 100644 --- a/src/buffer.h +++ b/src/buffer.h | |||
| @@ -379,7 +379,6 @@ struct buffer | |||
| 379 | /* Values of several buffer-local variables. */ | 379 | /* Values of several buffer-local variables. */ |
| 380 | /* tab-width is buffer-local so that redisplay can find it | 380 | /* tab-width is buffer-local so that redisplay can find it |
| 381 | in buffers that are not current. */ | 381 | in buffers that are not current. */ |
| 382 | Lisp_Object case_fold_search_; | ||
| 383 | Lisp_Object tab_width_; | 382 | Lisp_Object tab_width_; |
| 384 | Lisp_Object fill_column_; | 383 | Lisp_Object fill_column_; |
| 385 | Lisp_Object left_margin_; | 384 | Lisp_Object left_margin_; |
diff --git a/src/editfns.c b/src/editfns.c index 49d552c4a75..aa410ea7091 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -1785,7 +1785,7 @@ determines whether case is significant or ignored. */) | |||
| 1785 | register EMACS_INT begp1, endp1, begp2, endp2, temp; | 1785 | register EMACS_INT begp1, endp1, begp2, endp2, temp; |
| 1786 | register struct buffer *bp1, *bp2; | 1786 | register struct buffer *bp1, *bp2; |
| 1787 | register Lisp_Object trt | 1787 | register Lisp_Object trt |
| 1788 | = (!NILP (BVAR (current_buffer, case_fold_search)) | 1788 | = (!NILP (Vcase_fold_search) |
| 1789 | ? BVAR (current_buffer, case_canon_table) : Qnil); | 1789 | ? BVAR (current_buffer, case_canon_table) : Qnil); |
| 1790 | ptrdiff_t chars = 0; | 1790 | ptrdiff_t chars = 0; |
| 1791 | ptrdiff_t i1, i2, i1_byte, i2_byte; | 1791 | ptrdiff_t i1, i2, i1_byte, i2_byte; |
| @@ -4367,7 +4367,7 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer. */) | |||
| 4367 | 4367 | ||
| 4368 | if (XFIXNUM (c1) == XFIXNUM (c2)) | 4368 | if (XFIXNUM (c1) == XFIXNUM (c2)) |
| 4369 | return Qt; | 4369 | return Qt; |
| 4370 | if (NILP (BVAR (current_buffer, case_fold_search))) | 4370 | if (NILP (Vcase_fold_search)) |
| 4371 | return Qnil; | 4371 | return Qnil; |
| 4372 | 4372 | ||
| 4373 | i1 = XFIXNAT (c1); | 4373 | i1 = XFIXNAT (c1); |
diff --git a/src/minibuf.c b/src/minibuf.c index 58adde1bf66..0d5b375e450 100644 --- a/src/minibuf.c +++ b/src/minibuf.c | |||
| @@ -2320,7 +2320,6 @@ syms_of_minibuf (void) | |||
| 2320 | 2320 | ||
| 2321 | DEFSYM (Qcurrent_input_method, "current-input-method"); | 2321 | DEFSYM (Qcurrent_input_method, "current-input-method"); |
| 2322 | DEFSYM (Qactivate_input_method, "activate-input-method"); | 2322 | DEFSYM (Qactivate_input_method, "activate-input-method"); |
| 2323 | DEFSYM (Qcase_fold_search, "case-fold-search"); | ||
| 2324 | DEFSYM (Qmetadata, "metadata"); | 2323 | DEFSYM (Qmetadata, "metadata"); |
| 2325 | DEFSYM (Qcycle_sort_function, "cycle-sort-function"); | 2324 | DEFSYM (Qcycle_sort_function, "cycle-sort-function"); |
| 2326 | 2325 | ||
diff --git a/src/search.c b/src/search.c index 2996d32fca1..75a67ff3223 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -281,7 +281,7 @@ looking_at_1 (Lisp_Object string, bool posix, bool modify_data) | |||
| 281 | struct regexp_cache *cache_entry = compile_pattern ( | 281 | struct regexp_cache *cache_entry = compile_pattern ( |
| 282 | string, | 282 | string, |
| 283 | modify_match_data ? &search_regs : NULL, | 283 | modify_match_data ? &search_regs : NULL, |
| 284 | (!NILP (BVAR (current_buffer, case_fold_search)) | 284 | (!NILP (Vcase_fold_search) |
| 285 | ? BVAR (current_buffer, case_canon_table) : Qnil), | 285 | ? BVAR (current_buffer, case_canon_table) : Qnil), |
| 286 | posix, | 286 | posix, |
| 287 | !NILP (BVAR (current_buffer, enable_multibyte_characters))); | 287 | !NILP (BVAR (current_buffer, enable_multibyte_characters))); |
| @@ -402,7 +402,7 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, | |||
| 402 | struct regexp_cache *cache_entry | 402 | struct regexp_cache *cache_entry |
| 403 | = compile_pattern (regexp, | 403 | = compile_pattern (regexp, |
| 404 | modify_match_data ? &search_regs : NULL, | 404 | modify_match_data ? &search_regs : NULL, |
| 405 | (!NILP (BVAR (current_buffer, case_fold_search)) | 405 | (!NILP (Vcase_fold_search) |
| 406 | ? BVAR (current_buffer, case_canon_table) | 406 | ? BVAR (current_buffer, case_canon_table) |
| 407 | : Qnil), | 407 | : Qnil), |
| 408 | posix, | 408 | posix, |
| @@ -1068,10 +1068,10 @@ search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, | |||
| 1068 | BVAR (current_buffer, case_eqv_table)); | 1068 | BVAR (current_buffer, case_eqv_table)); |
| 1069 | 1069 | ||
| 1070 | np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE, | 1070 | np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE, |
| 1071 | (!NILP (BVAR (current_buffer, case_fold_search)) | 1071 | (!NILP (Vcase_fold_search) |
| 1072 | ? BVAR (current_buffer, case_canon_table) | 1072 | ? BVAR (current_buffer, case_canon_table) |
| 1073 | : Qnil), | 1073 | : Qnil), |
| 1074 | (!NILP (BVAR (current_buffer, case_fold_search)) | 1074 | (!NILP (Vcase_fold_search) |
| 1075 | ? BVAR (current_buffer, case_eqv_table) | 1075 | ? BVAR (current_buffer, case_eqv_table) |
| 1076 | : Qnil), | 1076 | : Qnil), |
| 1077 | posix); | 1077 | posix); |
| @@ -3402,7 +3402,7 @@ If RAW is non-nil, just return the actual bytecode. */) | |||
| 3402 | { | 3402 | { |
| 3403 | struct regexp_cache *cache_entry | 3403 | struct regexp_cache *cache_entry |
| 3404 | = compile_pattern (regexp, NULL, | 3404 | = compile_pattern (regexp, NULL, |
| 3405 | (!NILP (BVAR (current_buffer, case_fold_search)) | 3405 | (!NILP (Vcase_fold_search) |
| 3406 | ? BVAR (current_buffer, case_canon_table) : Qnil), | 3406 | ? BVAR (current_buffer, case_canon_table) : Qnil), |
| 3407 | false, | 3407 | false, |
| 3408 | !NILP (BVAR (current_buffer, | 3408 | !NILP (BVAR (current_buffer, |