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 <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2023-07-09 17:09:16 +10:00 committed by Carles Cufí
parent 76c1a2019a
commit 1c2dba2107

View file

@ -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];