GNU bug report logs -
#48264
28.0.50; Changing the default for DEFVAR_PER_BUFFER variables takes O(#buffers) time
Previous Next
Full log
View this message in rfc822 format
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Spencer Baugh <sbaugh <at> catern.com>
>> Cc: 48264 <at> debbugs.gnu.org
>> Date: Sat, 08 May 2021 09:35:31 -0400
>> If you think such a conditionally-compiled runtime check would be
>> acceptable for applying these changes, I can go ahead and write that.
>
> Yes, I think so. But if Lars or Stefan think differently, I might
> reconsider.
In the process of implementing the runtime check, I, of course, came up
with a better compile-time check. How about this?
---
src/buffer.h | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/buffer.h b/src/buffer.h
index f78046a9a8..a8a662b1ed 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -280,13 +280,25 @@ struct buffer_text
bool_bf redisplay : 1;
};
+/* This structure is used purely as a list of field names that are
+ permitted for use with BVAR; it's never actually instantiated. */
+struct bvar_permanent_locals {
+ char name, filename, directory, backed_up, save_length, auto_save_file_name,
+ read_only, mark, local_var_alist, major_mode, local_minor_modes, mode_name,
+ keymap, downcase_table, upcase_table, case_canon_table, case_eqv_table,
+ mark_active, enable_multibyte_characters, file_format,
+ auto_save_file_format, width_table, pt_marker, begv_marker, zv_marker,
+ point_before_scroll, file_truename, invisibility_spec, last_selected_window,
+ display_count, display_time, undo_list;
+};
/* Most code should use this macro to access Lisp fields in struct buffer. */
-#define BVAR(buf, field) ((buf)->field ## _)
+#define BVAR(buf, field) \
+ *((void) offsetof (struct bvar_permanent_locals, field), &(buf)->field ## _)
-#define BVAR_OR_DEFAULT(buf, field) (EQ (BVAR ((buf), field), Qunbound) \
- ? BVAR (&buffer_defaults, field) \
- : BVAR ((buf), field))
+#define BVAR_OR_DEFAULT(buf, field) (EQ ((buf)->field ## _, Qunbound) \
+ ? buffer_defaults.field ## _ \
+ : (buf)->field ## _)
/* Max number of builtin per-buffer variables. */
enum { MAX_PER_BUFFER_VARS = 50 };
--
2.31.1
This bug report was last modified 2 years and 289 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.