>From 2b377704f46081f2348dfc5650820ac9b5485758 Mon Sep 17 00:00:00 2001
From: Josef Cejka <jce...@suse.de>
Date: Wed, 3 Aug 2022 13:33:21 +0200
Subject: [PATCH] debuginfod: optimize regular expressions in groom()

Check if applying of -I and -X during grooming is enabled
before the regular expressions are matched.

Signed-off-by: Josef Cejka <jce...@suse.de>
---
 debuginfod/debuginfod.cxx | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 303ffe00..a089d0bd 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -3580,11 +3580,17 @@ void groom()
       int64_t fileid = sqlite3_column_int64 (files, 1);
       const char* filename = ((const char*) sqlite3_column_text (files, 2) ?: 
"");
       struct stat s;
-      bool reg_include = !regexec (&file_include_regex, filename, 0, 0, 0);
-      bool reg_exclude = !regexec (&file_exclude_regex, filename, 0, 0, 0);
+      bool regex_file_drop = 0;
+
+      if (regex_groom)
+        {
+          bool reg_include = !regexec (&file_include_regex, filename, 0, 0, 0);
+          bool reg_exclude = !regexec (&file_exclude_regex, filename, 0, 0, 0);
+          regex_file_drop = reg_exclude && !reg_include;
+        }
 
       rc = stat(filename, &s);
-      if ( (regex_groom && reg_exclude && !reg_include) ||  rc < 0 || (mtime 
!= (int64_t) s.st_mtime) )
+      if ( regex_file_drop ||  rc < 0 || (mtime != (int64_t) s.st_mtime) )
         {
           if (verbose > 2)
             obatched(clog) << "groom: stale file=" << filename << " mtime=" << 
mtime << endl;
-- 
2.35.3



Reply via email to