From 65b73ce4342cdfa2486be406e9df5f9effb7fd7c Mon Sep 17 00:00:00 2001 From: Dmitry Goncharov Date: Sun, 30 May 2021 16:21:22 -0400 Subject: [PATCH] [SV 60699] Avoid calling strlen() repeatedly in a loop * src/variable.c (lookup_pattern_var): Accept target length parameter. (initialize_file_variables): Pass computed target length to lookup. --- src/variable.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/variable.c b/src/variable.c index 92582625..3d7301b1 100644 --- a/src/variable.c +++ b/src/variable.c @@ -98,10 +98,10 @@ create_pattern_var (const char *target, const char *suffix) /* Look up a target in the pattern-specific variable list. */ static struct pattern_var * -lookup_pattern_var (struct pattern_var *start, const char *target) +lookup_pattern_var (struct pattern_var *start, const char *target, + size_t targlen) { struct pattern_var *p; - size_t targlen = strlen (target); for (p = start ? start->next : pattern_vars; p != 0; p = p->next) { @@ -604,8 +604,9 @@ initialize_file_variables (struct file *file, int reading) if (!reading && !file->pat_searched) { struct pattern_var *p; + const size_t targlen = strlen (file->name); - p = lookup_pattern_var (0, file->name); + p = lookup_pattern_var (0, file->name, targlen); if (p != 0) { struct variable_set_list *global = current_variable_set_list; @@ -644,7 +645,7 @@ initialize_file_variables (struct file *file, int reading) v->export = p->variable.export; v->private_var = p->variable.private_var; } - while ((p = lookup_pattern_var (p, file->name)) != 0); + while ((p = lookup_pattern_var (p, file->name, targlen)) != 0); current_variable_set_list = global; }