]> git.ipfire.org Git - pakfire.git/commitdiff
parser: expand: Tidy up some code
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Mar 2021 11:47:01 +0000 (11:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Mar 2021 11:47:01 +0000 (11:47 +0000)
No functional changes

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser.c

index cceaed924b184e2baba297481e467efe0ac5984d..a8a238e5df9e711eb517dcbca21c452e27dbd9a8 100644 (file)
@@ -340,9 +340,13 @@ PAKFIRE_EXPORT char* pakfire_parser_expand(PakfireParser parser,
        if (!value)
                return NULL;
 
+       // Create a working copy of the string we are expanding
+       char* buffer = strdup(value);
+
+       // Fast path to check if there are any variables in here whatsoever
        char* pos = strchr(value, '%');
        if (!pos)
-               return strdup(value);
+               return buffer;
 
        // Compile the regular expression
        regex_t preg;
@@ -357,9 +361,6 @@ PAKFIRE_EXPORT char* pakfire_parser_expand(PakfireParser parser,
                return NULL;
        }
 
-       // Create a working copy of the string we are expanding
-       char* buffer = strdup(value);
-
        char* variable = NULL;
        char* pattern = NULL;
        const size_t max_groups = 2;