From: Spencer Baugh <sbaugh@catern.com>
To: emacs-devel@gnu.org
Cc: Spencer Baugh <sbaugh@catern.com>,
Arnold Noronha <arnold@tdrhq.com>,
Stefan Monnier <monnier@iro.umontreal.ca>,
Dmitry Gutov <dgutov@yandex.ru>
Subject: [PATCH 10/10] Don't iterate over all buffers in set_default_internal
Date: Thu, 19 Nov 2020 10:38:14 -0500 [thread overview]
Message-ID: <20201119153814.17541-11-sbaugh@catern.com> (raw)
In-Reply-To: <87mtzil519.fsf@catern.com>
The main change here is in set_default_internal, where we remove the
loop over all live buffers. Instead, we only set the default value.
There are some followup changes implied by that.
When looking up a BUFFER_OBJFWDP variable, we now need to call
bvar_get, so that we look at the default value, instead of calling
per_buffer_value, which now won't be updated by LET_DEFAULT.
More complex is the change to set_internal.
Previously, if we were in the following scenario, which we'll refer to
as scenario A:
- We are in the scope of a let_default binding for some variable,
- the current buffer is the buffer which created that let binding,
- and we call setq for that variable.
The variable would not become buffer-local after the setq, because of
this check in set_internal. But, nevertheless, the value we'd see for
the variable would still appear different in the current buffer from
other buffers. See the first, minor bug mentioned in bug#44733.
This wouldn't work with these changes, because merely setting a value
in struct buffer is not enough to change the value visible to Lisp:
the variable also must become buffer-local.
By removing this check in set_internal, the variable will become
buffer-local when set in scenario A, so its binding will be visible.
Finally, the change to do_one_unbind is required by the change to
set_internal, to preserve the old unwinding behavior of let_default
bindings.
The old behavior of let_default is that if we setq in a buffer other
than the one which created the let_default binding, our binding
wouldn't be unwound after the let_default was done. But if we setq in
the buffer that created the let_default binding (that is, in scenario
A) then that binding would be unwound.
Previously, this unwinding behavior was implemented by
set_default_internal. Now, this change to do_one_unbind makes it
perform this unwinding in the buffer that created the let_default
binding.
---
src/buffer.c | 2 +-
src/data.c | 30 +++---------------------------
src/eval.c | 18 ++++++++++++++++--
3 files changed, 20 insertions(+), 30 deletions(-)
diff --git a/src/buffer.c b/src/buffer.c
index 6bcf1ad596..a8e00ca876 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1251,7 +1251,7 @@ buffer_local_value (Lisp_Object variable, Lisp_Object buffer)
{
lispfwd fwd = SYMBOL_FWD (sym);
if (BUFFER_OBJFWDP (fwd))
- result = per_buffer_value (buf, XBUFFER_OBJFWD (fwd)->offset);
+ result = bvar_get (buf, XBUFFER_OBJFWD (fwd)->offset);
else
result = Fdefault_value (variable);
break;
diff --git a/src/data.c b/src/data.c
index 6558985668..49a29092f9 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1004,8 +1004,8 @@ do_symval_forwarding (lispfwd valcontents)
return *XOBJFWD (valcontents)->objvar;
case Lisp_Fwd_Buffer_Obj:
- return per_buffer_value (current_buffer,
- XBUFFER_OBJFWD (valcontents)->offset);
+ return bvar_get (current_buffer,
+ XBUFFER_OBJFWD (valcontents)->offset);
case Lisp_Fwd_Kboard_Obj:
/* We used to simply use current_kboard here, but from Lisp
@@ -1441,8 +1441,7 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, Lisp_Object where,
int offset = XBUFFER_OBJFWD (innercontents)->offset;
int idx = PER_BUFFER_IDX (offset);
if (idx > 0
- && bindflag == SET_INTERNAL_SET
- && !let_shadows_buffer_binding_p (sym))
+ && bindflag == SET_INTERNAL_SET)
SET_PER_BUFFER_VALUE_P (buf, idx, 1);
}
@@ -1716,30 +1715,7 @@ set_default_internal (Lisp_Object symbol, Lisp_Object value,
if (BUFFER_OBJFWDP (valcontents))
{
int offset = XBUFFER_OBJFWD (valcontents)->offset;
- int idx = PER_BUFFER_IDX (offset);
-
set_per_buffer_default (offset, value);
-
- /* If this variable is not always local in all buffers,
- set it in the buffers that don't nominally have a local value. */
- if (idx > 0)
- {
- Lisp_Object buf, tail;
-
- /* Do this only in live buffers, so that if there are
- a lot of buffers which are dead, that doesn't slow
- down let-binding of variables that are
- automatically local when set, like
- case-fold-search. This is for Lisp programs that
- let-bind such variables in their inner loops. */
- FOR_EACH_LIVE_BUFFER (tail, buf)
- {
- struct buffer *b = XBUFFER (buf);
-
- if (!PER_BUFFER_VALUE_P (b, idx))
- set_per_buffer_value (b, offset, value);
- }
- }
}
else
set_internal (symbol, value, Qnil, bindflag);
diff --git a/src/eval.c b/src/eval.c
index 76708e6e7e..7a8e314550 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -3497,12 +3497,26 @@ do_one_unbind (union specbinding *this_binding, bool unwinding,
}
/* Come here only if make_local_foo was used for the first time
on this var within this let. */
- FALLTHROUGH;
- case SPECPDL_LET_DEFAULT:
set_default_internal (specpdl_symbol (this_binding),
specpdl_old_value (this_binding),
bindflag);
break;
+ case SPECPDL_LET_DEFAULT:
+ {
+ Lisp_Object symbol = specpdl_symbol (this_binding);
+ Lisp_Object where = specpdl_where (this_binding);
+ Lisp_Object old_value = specpdl_old_value (this_binding);
+ eassert (BUFFERP (where));
+
+ /* If this was a local binding, reset the value in the appropriate
+ buffer, but only if that buffer's binding still exists. */
+ if (!NILP (Flocal_variable_p (symbol, where)))
+ set_internal (symbol, old_value, where, bindflag);
+ set_default_internal (specpdl_symbol (this_binding),
+ specpdl_old_value (this_binding),
+ bindflag);
+ }
+ break;
case SPECPDL_LET_LOCAL:
{
Lisp_Object symbol = specpdl_symbol (this_binding);
--
2.28.0
next prev parent reply other threads:[~2020-11-19 15:38 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-14 16:34 ido-switch-buffer is slow with many buffers; others are fast catern
2020-11-14 18:22 ` Stefan Monnier
2020-11-14 20:06 ` sbaugh
2020-11-14 23:00 ` Stefan Monnier
2020-11-14 23:16 ` Dmitry Gutov
2020-11-15 0:19 ` Spencer Baugh
2020-11-15 15:15 ` Stefan Monnier
2020-11-15 20:49 ` Spencer Baugh
2020-11-15 23:58 ` Arnold Noronha
2020-11-19 15:38 ` [PATCH 00/10] Speeding up DEFVAR_PER_BUFFER (Was: ido-switch-buffer is slow) Spencer Baugh
2020-11-19 17:29 ` [PATCH 00/10] Speeding up DEFVAR_PER_BUFFER Stefan Monnier
2020-11-22 2:34 ` [PATCH v2 00/16] " Spencer Baugh
2020-11-22 2:34 ` [PATCH v2 01/16] Add a test for let-binding unwinding Spencer Baugh
2020-11-25 20:53 ` Stefan Monnier
2020-11-30 17:31 ` Spencer Baugh
2020-12-01 16:44 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 02/16] Assert not local-variable-p after setq in let_default binding Spencer Baugh
2020-11-25 20:54 ` Stefan Monnier
2020-12-01 16:45 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 03/16] Stop checking the constant default for enable_multibyte_characters Spencer Baugh
2020-11-25 20:57 ` Stefan Monnier
2020-12-01 16:52 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 04/16] Take buffer field name in DEFVAR_PER_BUFFER Spencer Baugh
2020-12-01 16:56 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 05/16] Add BVAR_DEFAULT for access to buffer defaults Spencer Baugh
2020-12-01 17:00 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 06/16] Use bset_* functions instead of BVAR Spencer Baugh
2020-12-01 17:12 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 07/16] Take offset not idx in PER_BUFFER_VALUE_P Spencer Baugh
2020-12-01 17:20 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 08/16] Combine unnecessarily separate loops in buffer.c Spencer Baugh
2020-12-01 17:22 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 09/16] Add and use BUFFER_DEFAULT_VALUE_P Spencer Baugh
2020-12-01 17:24 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 10/16] Add and use KILL_PER_BUFFER_VALUE Spencer Baugh
2020-12-01 17:26 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 11/16] Assert that PER_BUFFER_IDX for Lisp variables is not 0 Spencer Baugh
2020-12-01 17:32 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 12/16] Rearrange set_internal for buffer forwarded symbols Spencer Baugh
2020-12-01 17:35 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 13/16] Get rid of buffer_permanent_local_flags array Spencer Baugh
2020-11-22 16:16 ` Eli Zaretskii
2020-12-01 17:39 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 14/16] Remove unnecessary Qunbound check Spencer Baugh
2020-12-01 17:40 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 15/16] Remove local_flags array in struct buffer Spencer Baugh
2020-11-22 20:04 ` Stefan Monnier
2020-12-01 17:57 ` Eli Zaretskii
2020-11-22 2:34 ` [PATCH v2 16/16] Remove usage of buffer_local_flags Spencer Baugh
2020-12-01 18:05 ` Eli Zaretskii
2020-11-22 11:19 ` [PATCH v2 00/16] Speeding up DEFVAR_PER_BUFFER Kévin Le Gouguec
2020-11-22 16:12 ` Eli Zaretskii
2020-11-22 16:28 ` Spencer Baugh
2020-11-22 17:13 ` Eli Zaretskii
2020-11-29 17:41 ` Spencer Baugh
2020-11-30 18:32 ` Eli Zaretskii
2020-11-30 20:11 ` Spencer Baugh
2020-11-30 22:10 ` Stefan Monnier
2020-11-30 22:26 ` Andrea Corallo via Emacs development discussions.
2020-12-01 15:15 ` Eli Zaretskii
2020-12-01 15:56 ` Stefan Monnier
2020-12-01 15:10 ` Eli Zaretskii
2020-12-01 15:20 ` Spencer Baugh
2020-12-01 16:01 ` Stefan Monnier
2020-12-01 16:16 ` Eli Zaretskii
2020-12-01 18:10 ` Eli Zaretskii
2020-11-22 20:11 ` Stefan Monnier
2020-11-19 15:38 ` [PATCH 01/10] Take buffer field name in DEFVAR_PER_BUFFER Spencer Baugh
2020-11-19 15:38 ` [PATCH 02/10] Add bset_save_length and use it Spencer Baugh
2020-11-19 15:38 ` [PATCH 03/10] Use bset_last_selected_window everywhere Spencer Baugh
2020-11-19 15:38 ` [PATCH 04/10] Use bset_enable_multibyte_characters everywhere Spencer Baugh
2020-11-19 15:38 ` [PATCH 05/10] Add BVAR_DEFAULT for access to buffer defaults Spencer Baugh
2020-11-19 15:38 ` [PATCH 06/10] Disallow using BVAR as an lvalue Spencer Baugh
2020-11-19 15:38 ` [PATCH 07/10] Reorder buffer.h for upcoming rework of BVAR Spencer Baugh
2020-11-19 15:38 ` [PATCH 08/10] Make cache_long_scans buffer-local when setting it Spencer Baugh
2020-11-19 15:38 ` [PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding Spencer Baugh
2020-11-19 18:08 ` Stefan Monnier
2020-11-19 18:21 ` Eli Zaretskii
2020-11-19 15:38 ` Spencer Baugh [this message]
2020-11-19 18:21 ` [PATCH 10/10] Don't iterate over all buffers in set_default_internal Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201119153814.17541-11-sbaugh@catern.com \
--to=sbaugh@catern.com \
--cc=arnold@tdrhq.com \
--cc=dgutov@yandex.ru \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.