[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/10] Don't iterate over all buffers in set_default_internal
From: |
Spencer Baugh |
Subject: |
[PATCH 10/10] Don't iterate over all buffers in set_default_internal |
Date: |
Thu, 19 Nov 2020 10:38:14 -0500 |
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
- Re: [PATCH 00/10] Speeding up DEFVAR_PER_BUFFER, (continued)
- Re: [PATCH 00/10] Speeding up DEFVAR_PER_BUFFER, Stefan Monnier, 2020/11/19
- [PATCH 03/10] Use bset_last_selected_window everywhere, Spencer Baugh, 2020/11/19
- [PATCH 01/10] Take buffer field name in DEFVAR_PER_BUFFER, Spencer Baugh, 2020/11/19
- [PATCH 06/10] Disallow using BVAR as an lvalue, Spencer Baugh, 2020/11/19
- [PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding, Spencer Baugh, 2020/11/19
- Re: [PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding, Stefan Monnier, 2020/11/19
- Re: [PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding, Eli Zaretskii, 2020/11/19
- [PATCH 05/10] Add BVAR_DEFAULT for access to buffer defaults, Spencer Baugh, 2020/11/19
- [PATCH 08/10] Make cache_long_scans buffer-local when setting it, Spencer Baugh, 2020/11/19
- [PATCH 07/10] Reorder buffer.h for upcoming rework of BVAR, Spencer Baugh, 2020/11/19
- [PATCH 10/10] Don't iterate over all buffers in set_default_internal,
Spencer Baugh <=
- Re: [PATCH 10/10] Don't iterate over all buffers in set_default_internal, Stefan Monnier, 2020/11/19