From 7cb253d95d00c706c1b69d107a8265950b1c430a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 17 Jul 2022 09:56:32 +0300 Subject: [PATCH 54/54] Inline action_by_number() See osdn #45123 Signed-off-by: Marko Lindqvist --- common/actions.c | 21 +-------------------- common/actions.h | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/common/actions.c b/common/actions.c index e764634828..121e1435b8 100644 --- a/common/actions.c +++ b/common/actions.c @@ -94,6 +94,7 @@ struct obligatory_req { #define ACTPROB_VAL_NOT_IMPL 254 static struct action *actions[MAX_NUM_ACTIONS]; +struct action **_actions = actions; struct action_auto_perf auto_perfs[MAX_NUM_ACTION_AUTO_PERFORMERS]; static bool actions_initialized = FALSE; @@ -1714,26 +1715,6 @@ bool action_id_exists(const action_id act_id) return gen_action_is_valid(act_id) && actions[act_id]; } -/**********************************************************************//** - Return the action with the given id. - - Returns NULL if no action with the given id exists. -**************************************************************************/ -struct action *action_by_number(action_id act_id) -{ - if (!action_id_exists(act_id)) { - /* Nothing to return. */ - - log_verbose("Asked for non existing action numbered %d", act_id); - - return NULL; - } - - fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id); - - return actions[act_id]; -} - /**********************************************************************//** Return the action with the given name. diff --git a/common/actions.h b/common/actions.h index 7f3795ac7f..2238228fc1 100644 --- a/common/actions.h +++ b/common/actions.h @@ -639,7 +639,22 @@ bool actions_are_ready(void); bool action_id_exists(const action_id act_id); -struct action *action_by_number(action_id act_id); +extern struct action **_actions; +/**********************************************************************//** + Return the action with the given id. + + Returns NULL if no action with the given id exists. +**************************************************************************/ +static inline struct action *action_by_number(action_id act_id) +{ + if (!gen_action_is_valid((enum gen_action)act_id)) { + return NULL; + } + + /* We return NULL if there's NULL there, no need to special case it */ + return _actions[act_id]; +} + struct action *action_by_rule_name(const char *name); enum action_actor_kind action_get_actor_kind(const struct action *paction); -- 2.35.1