]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 60699] Avoid calling strlen() repeatedly in a loop
authorDmitry Goncharov <dgoncharov@users.sf.net>
Sun, 30 May 2021 20:21:22 +0000 (16:21 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 25 Jul 2021 21:15:38 +0000 (17:15 -0400)
* src/variable.c (lookup_pattern_var): Accept target length parameter.
(initialize_file_variables): Pass computed target length to lookup.

src/variable.c

index 9258262512aede0957f4ac88d0de8d84346e848d..3d7301b112e9e55c99159c807b7f28ad7f8b1f34 100644 (file)
@@ -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;
         }