[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding
From: |
Spencer Baugh |
Subject: |
[PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding |
Date: |
Thu, 19 Nov 2020 10:38:13 -0500 |
In SHOULD_USE_BUFFER_DEFAULTS, we have to extract the buffer field
index from buffer_local_flags.
If the buffer_local_flags Lisp_Object is 0, though, it means this
field in buffer_local_flags wasn't initialized, which means this field
is always buffer-local (and therefore doesn't use buffer_defaults).
Otherwise, it should be a fixnum. If it's less than 1, it also means
that this field is always buffer-local, and we shouldn't use
buffer_defaults.
Finally, if it's 1 or greater, it's a valid index into local_flags. If
local_flags is 0, that means there's no local value for this buffer
variable. Which means we should use buffer_defaults.
---
src/buffer.h | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/src/buffer.h b/src/buffer.h
index 077edb893a..d0e44c35bb 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -825,9 +825,31 @@ set_per_buffer_value (struct buffer *b, int offset,
Lisp_Object value)
*(Lisp_Object *)(offset + (char *) b) = value;
}
+INLINE bool
+SHOULD_USE_BUFFER_DEFAULTS(struct buffer *b, ptrdiff_t offset)
+{
+ Lisp_Object obj = *((Lisp_Object *) (offset + (char *) &buffer_local_flags));
+ if (obj.i == 0)
+ return false;
+ int idx = XFIXNUM(obj);
+ if (idx < 1)
+ return false;
+ return b->local_flags[idx] == 0;
+}
+
+INLINE Lisp_Object
+bvar_get(struct buffer *b, ptrdiff_t offset)
+{
+ if (SHOULD_USE_BUFFER_DEFAULTS(b, offset)) {
+ return per_buffer_value(&buffer_defaults, offset);
+ } else {
+ return per_buffer_value(b, offset);
+ }
+}
+
/* Most code should use this macro to access Lisp fields in struct buffer. */
-#define BVAR(buf, field) ((void)0, (buf)->field ## _)
+#define BVAR(buf, field) bvar_get(buf, PER_BUFFER_VAR_OFFSET (field))
/* Access a BVAR from buffer_defaults */
#define BVAR_DEFAULT(field) (buffer_defaults.field ## _)
--
2.28.0
- Re: ido-switch-buffer is slow with many buffers; others are fast, (continued)
- Re: ido-switch-buffer is slow with many buffers; others are fast, Stefan Monnier, 2020/11/15
- Re: ido-switch-buffer is slow with many buffers; others are fast, Spencer Baugh, 2020/11/15
- Re: ido-switch-buffer is slow with many buffers; others are fast, Arnold Noronha, 2020/11/15
- [PATCH 02/10] Add bset_save_length and use it, Spencer Baugh, 2020/11/19
- [PATCH 04/10] Use bset_enable_multibyte_characters everywhere, Spencer Baugh, 2020/11/19
- [PATCH 00/10] Speeding up DEFVAR_PER_BUFFER (Was: ido-switch-buffer is slow), Spencer Baugh, 2020/11/19
- 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 <=
- 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, 2020/11/19
- Re: [PATCH 10/10] Don't iterate over all buffers in set_default_internal, Stefan Monnier, 2020/11/19