[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 07/16] Take offset not idx in PER_BUFFER_VALUE_P
From: |
Spencer Baugh |
Subject: |
[PATCH v2 07/16] Take offset not idx in PER_BUFFER_VALUE_P |
Date: |
Sat, 21 Nov 2020 21:34:36 -0500 |
This also moves the common "idx == -1" check into PER_BUFFER_VALUE_P.
If idx == -1, it's guaranteed that the corresponding buffer field has
a per-buffer value. We do this check everywhere we call
PER_BUFFER_VALUE_P, so let's put it in the common code.
This is motivated by later commits which will get rid of idx.
---
src/buffer.c | 3 +--
src/buffer.h | 21 +++++++++++----------
src/data.c | 11 +++++------
3 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/src/buffer.c b/src/buffer.c
index aa951ca78f..a0bcbf38e5 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1297,8 +1297,7 @@ buffer_lisp_local_variables (struct buffer *buf, bool
clone)
static Lisp_Object
buffer_local_variables_1 (struct buffer *buf, int offset, Lisp_Object sym)
{
- int idx = PER_BUFFER_IDX (offset);
- if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
+ if (PER_BUFFER_VALUE_P (buf, offset)
&& SYMBOLP (PER_BUFFER_SYMBOL (offset)))
{
sym = NILP (sym) ? PER_BUFFER_SYMBOL (offset) : sym;
diff --git a/src/buffer.h b/src/buffer.h
index 770a5d03e6..69df791b53 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1420,16 +1420,6 @@ OVERLAY_POSITION (Lisp_Object p)
extern bool valid_per_buffer_idx (int);
-/* Value is true if the variable with index IDX has a local value
- in buffer B. */
-
-INLINE bool
-PER_BUFFER_VALUE_P (struct buffer *b, int idx)
-{
- eassert (valid_per_buffer_idx (idx));
- return b->local_flags[idx];
-}
-
/* Set whether per-buffer variable with index IDX has a buffer-local
value in buffer B. VAL zero means it hasn't. */
@@ -1496,6 +1486,17 @@ set_per_buffer_value (struct buffer *b, int offset,
Lisp_Object value)
*(Lisp_Object *)(offset + (char *) b) = value;
}
+/* Value is true if the variable with offset OFFSET has a local value
+ in buffer B. */
+
+INLINE bool
+PER_BUFFER_VALUE_P (struct buffer *b, int offset)
+{
+ int idx = PER_BUFFER_IDX (offset);
+ eassert (idx == -1 || valid_per_buffer_idx (idx));
+ return idx == -1 || b->local_flags[idx];
+}
+
/* Downcase a character C, or make no change if that cannot be done. */
INLINE int
downcase (int c)
diff --git a/src/data.c b/src/data.c
index 384c259220..47a1a6640f 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1123,7 +1123,7 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object
newval,
{
struct buffer *b = XBUFFER (buf);
- if (! PER_BUFFER_VALUE_P (b, idx))
+ if (! PER_BUFFER_VALUE_P (b, offset))
set_per_buffer_value (b, offset, newval);
}
}
@@ -1440,8 +1440,8 @@ 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
- && !PER_BUFFER_VALUE_P (buf, idx))
+ if (bindflag == SET_INTERNAL_SET
+ && !PER_BUFFER_VALUE_P (buf, offset))
{
if (let_shadows_buffer_binding_p (sym))
set_default_internal (symbol, newval, bindflag);
@@ -1740,7 +1740,7 @@ set_default_internal (Lisp_Object symbol, Lisp_Object
value,
{
struct buffer *b = XBUFFER (buf);
- if (!PER_BUFFER_VALUE_P (b, idx))
+ if (!PER_BUFFER_VALUE_P (b, offset))
set_per_buffer_value (b, offset, value);
}
}
@@ -2077,8 +2077,7 @@ BUFFER defaults to the current buffer. */)
if (BUFFER_OBJFWDP (valcontents))
{
int offset = XBUFFER_OBJFWD (valcontents)->offset;
- int idx = PER_BUFFER_IDX (offset);
- if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
+ if (PER_BUFFER_VALUE_P (buf, offset))
return Qt;
}
return Qnil;
--
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 v2 00/16] Speeding up DEFVAR_PER_BUFFER, Spencer Baugh, 2020/11/21
- [PATCH v2 01/16] Add a test for let-binding unwinding, Spencer Baugh, 2020/11/21
- [PATCH v2 05/16] Add BVAR_DEFAULT for access to buffer defaults, Spencer Baugh, 2020/11/21
- [PATCH v2 02/16] Assert not local-variable-p after setq in let_default binding, Spencer Baugh, 2020/11/21
- [PATCH v2 03/16] Stop checking the constant default for enable_multibyte_characters, Spencer Baugh, 2020/11/21
- [PATCH v2 04/16] Take buffer field name in DEFVAR_PER_BUFFER, Spencer Baugh, 2020/11/21
- [PATCH v2 08/16] Combine unnecessarily separate loops in buffer.c, Spencer Baugh, 2020/11/21
- [PATCH v2 09/16] Add and use BUFFER_DEFAULT_VALUE_P, Spencer Baugh, 2020/11/21
- [PATCH v2 06/16] Use bset_* functions instead of BVAR, Spencer Baugh, 2020/11/21
- [PATCH v2 07/16] Take offset not idx in PER_BUFFER_VALUE_P,
Spencer Baugh <=
- [PATCH v2 11/16] Assert that PER_BUFFER_IDX for Lisp variables is not 0, Spencer Baugh, 2020/11/21
- [PATCH v2 14/16] Remove unnecessary Qunbound check, Spencer Baugh, 2020/11/21
- [PATCH v2 10/16] Add and use KILL_PER_BUFFER_VALUE, Spencer Baugh, 2020/11/21
- [PATCH v2 13/16] Get rid of buffer_permanent_local_flags array, Spencer Baugh, 2020/11/21
- Re: [PATCH v2 13/16] Get rid of buffer_permanent_local_flags array, Eli Zaretskii, 2020/11/22
- [PATCH v2 12/16] Rearrange set_internal for buffer forwarded symbols, Spencer Baugh, 2020/11/21
- [PATCH v2 15/16] Remove local_flags array in struct buffer, Spencer Baugh, 2020/11/21
- Re: [PATCH v2 15/16] Remove local_flags array in struct buffer, Stefan Monnier, 2020/11/22
- [PATCH v2 16/16] Remove usage of buffer_local_flags, Spencer Baugh, 2020/11/21
- Re: [PATCH v2 00/16] Speeding up DEFVAR_PER_BUFFER, Kévin Le Gouguec, 2020/11/22