From 1c2dba2107252e2632f58439c5b74f27505d4723 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sun, 9 Jul 2023 17:09:16 +1000 Subject: [PATCH] drivers: modem: cache delimiter string length Cache the delimiter string length in `parse_params`, instead of calculating it on each character in the match buffer. Signed-off-by: Jordan Yates --- drivers/modem/modem_cmd_handler.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/modem/modem_cmd_handler.c b/drivers/modem/modem_cmd_handler.c index 1eae992642..02306554d3 100644 --- a/drivers/modem/modem_cmd_handler.c +++ b/drivers/modem/modem_cmd_handler.c @@ -111,7 +111,7 @@ static int parse_params(struct modem_cmd_handler_data *data, size_t match_len, uint8_t **argv, size_t argv_len, uint16_t *argc) { int count = 0; - size_t begin, end, i; + size_t delim_len, begin, end, i; bool quoted = false; if (!data || !data->match_buf || !match_len || !cmd || !argv || !argc) { @@ -120,6 +120,7 @@ static int parse_params(struct modem_cmd_handler_data *data, size_t match_len, begin = cmd->cmd_len; end = cmd->cmd_len; + delim_len = strlen(cmd->delim); while (end < match_len) { /* Don't look for delimiters in the middle of a quoted parameter */ if (data->match_buf[end] == '"') { @@ -130,7 +131,7 @@ static int parse_params(struct modem_cmd_handler_data *data, size_t match_len, continue; } /* Look for delimiter characters */ - for (i = 0; i < strlen(cmd->delim); i++) { + for (i = 0; i < delim_len; i++) { if (data->match_buf[end] == cmd->delim[i]) { /* mark a parameter beginning */ argv[*argc] = &data->match_buf[begin];