[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master 91b2b3654f2: Turn macros into enums in keyboard.h
From: |
Pip Cet |
Subject: |
Re: master 91b2b3654f2: Turn macros into enums in keyboard.h |
Date: |
Fri, 17 Jan 2025 17:42:00 +0000 |
"Stefan Kangas" <stefankangas@gmail.com> writes:
> branch: master
> commit 91b2b3654f2dcf79c15a11cfe1130df6638b4a4e
> Author: Stefan Kangas <stefankangas@gmail.com>
> Commit: Stefan Kangas <stefankangas@gmail.com>
>
> Turn macros into enums in keyboard.h
>
> * src/keyboard.h (item_property_idx, menu_item_pane_idx): Turn macros
> into enums.
> (ITEM_PROPERTY_MAX): New constant.
> * src/keyboard.c (parse_menu_item): Use above new constant.
> ---
> src/keyboard.c | 4 ++--
> src/keyboard.h | 60
> +++++++++++++++++++++++++++++++++-------------------------
> 2 files changed, 36 insertions(+), 28 deletions(-)
>
> diff --git a/src/keyboard.c b/src/keyboard.c
> index f36243dd442..c17210db8b8 100644
> --- a/src/keyboard.c
> +++ b/src/keyboard.c
> @@ -8713,10 +8713,10 @@ parse_menu_item (Lisp_Object item, int inmenubar)
>
> /* Create item_properties vector if necessary. */
> if (NILP (item_properties))
> - item_properties = make_nil_vector (ITEM_PROPERTY_ENABLE + 1);
> + item_properties = make_nil_vector (ITEM_PROPERTY_MAX + 1);
>
> /* Initialize optional entries. */
> - for (i = ITEM_PROPERTY_DEF; i < ITEM_PROPERTY_ENABLE; i++)
> + for (i = ITEM_PROPERTY_DEF; i < ITEM_PROPERTY_MAX; i++)
> ASET (item_properties, i, Qnil);
> ASET (item_properties, ITEM_PROPERTY_ENABLE, Qt);
Can we change this loop to include the last case, even though we know
it's probably overwritten by the next line? That would ensure it
continues working as intended if someone makes ITEM_PROPERTY_ENABLE !=
ITEM_PROPERTY_MAX.
In optimized builds, it's likely that the dead store is eliminated.
I've confirmed this for the (recent) GCC I'm using.
In general, of course, this code
for (int i = 0; i <= MAX; i++)
array [i] = 0;
array [someindex] = somevalue;
may actually be faster than
for (int i = 0; i <= MAX; i++)
if (i != someindex)
array [i] = 0;
array [someindex] = somevalue;
This is true even if somevalue is a constant, as it is here.
Pip
- Re: master 91b2b3654f2: Turn macros into enums in keyboard.h,
Pip Cet <=