From cce02ec4bca38b25a2683dbf98e2a514a18d1837 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 17 Jul 2022 10:01:00 +0300
Subject: [PATCH 24/24] Inline action_by_number()

See osdn #45123

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 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 2a3e28d4d5..3436352b2f 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -74,6 +74,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;
 
@@ -732,26 +733,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 a6ca5e4ef2..f2846b12c1 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -392,7 +392,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