From 0cf492601092b852526c3ee35fac2a21dd4afecc Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 3 Jun 2023 11:00:40 +0300 Subject: [PATCH 34/34] Improve unit_..._iterate() Call unit_..._array_last() just once, and not on every iteration. See osdn #47729 Signed-off-by: Marko Lindqvist --- common/unittype.h | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/common/unittype.h b/common/unittype.h index eba74cb90f..5acb94e309 100644 --- a/common/unittype.h +++ b/common/unittype.h @@ -846,15 +846,16 @@ void unit_class_flags_free(void); struct unit_type *unit_type_array_first(void); const struct unit_type *unit_type_array_last(void); -#define unit_type_iterate(_p) \ -{ \ - struct unit_type *_p = unit_type_array_first(); \ - if (NULL != _p) { \ - for (; _p <= unit_type_array_last(); _p++) { - -#define unit_type_iterate_end \ - } \ - } \ +#define unit_type_iterate(_p) \ +{ \ + struct unit_type *_p = unit_type_array_first(); \ + if (NULL != _p) { \ + const struct unit_type *_end_##_p = unit_type_array_last(); \ + for (; _p <= _end_##_p; _p++) { + +#define unit_type_iterate_end \ + } \ + } \ } #define unit_type_re_active_iterate(_p) \ @@ -898,15 +899,16 @@ void set_unit_type_caches(struct unit_type *ptype); struct unit_class *unit_class_array_first(void); const struct unit_class *unit_class_array_last(void); -#define unit_class_iterate(_p) \ -{ \ - struct unit_class *_p = unit_class_array_first(); \ - if (NULL != _p) { \ - for (; _p <= unit_class_array_last(); _p++) { +#define unit_class_iterate(_p) \ +{ \ + struct unit_class *_p = unit_class_array_first(); \ + if (NULL != _p) { \ + const struct unit_class *_end_##_p = unit_class_array_last(); \ + for (; _p <= _end_##_p; _p++) { -#define unit_class_iterate_end \ - } \ - } \ +#define unit_class_iterate_end \ + } \ + } \ } #define unit_class_re_active_iterate(_p) \ @@ -937,4 +939,4 @@ const struct unit_class *unit_class_array_last(void); } #endif /* __cplusplus */ -#endif /* FC__UNITTYPE_H */ +#endif /* FC__UNITTYPE_H */ -- 2.39.2