lib/cli: reduce strcmp in CLI hot paths
Er, no idea how anyone could ever have thought that it would be a good
idea to have a zillion of strcmp() calls in the CLI's active paths, just
to compare against things like "A.B.C.D".
Reduces 40k prefix list load time from 1.65s to 1.23s (1.34:1).
Acked-by: Paul Jakma <paul@jakma.org>
[v2: killed CMDS_* macros]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/lib/command.h b/lib/command.h
index 8eb0cbd..3a95df9 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -151,10 +151,25 @@
TOKEN_KEYWORD,
};
+enum cmd_terminal_type
+{
+ _TERMINAL_BUG = 0,
+ TERMINAL_LITERAL,
+ TERMINAL_OPTION,
+ TERMINAL_VARIABLE,
+ TERMINAL_VARARG,
+ TERMINAL_RANGE,
+ TERMINAL_IPV4,
+ TERMINAL_IPV4_PREFIX,
+ TERMINAL_IPV6,
+ TERMINAL_IPV6_PREFIX,
+};
+
/* Command description structure. */
struct cmd_token
{
enum cmd_token_type type;
+ enum cmd_terminal_type terminal;
/* Used for type == MULTIPLE */
vector multiple; /* vector of cmd_token, type == FINAL */
@@ -437,17 +452,6 @@
#endif /* VTYSH_EXTRACT_PL */
-/* Some macroes */
-#define CMD_OPTION(S) ((S[0]) == '[')
-#define CMD_VARIABLE(S) (((S[0]) >= 'A' && (S[0]) <= 'Z') || ((S[0]) == '<'))
-#define CMD_VARARG(S) ((S[0]) == '.')
-#define CMD_RANGE(S) ((S[0] == '<'))
-
-#define CMD_IPV4(S) ((strcmp ((S), "A.B.C.D") == 0))
-#define CMD_IPV4_PREFIX(S) ((strcmp ((S), "A.B.C.D/M") == 0))
-#define CMD_IPV6(S) ((strcmp ((S), "X:X::X:X") == 0))
-#define CMD_IPV6_PREFIX(S) ((strcmp ((S), "X:X::X:X/M") == 0))
-
/* Common descriptions. */
#define SHOW_STR "Show running system information\n"
#define IP_STR "IP information\n"