From 043ab3bbf0b20b2a738c8f490a28f768356988df Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Thu, 18 Feb 2021 21:14:11 +0100 Subject: [PATCH] tarfilter: Compile prefix pattern only once According to Debian bug #978742, mmtarfilter has a slow performance with many path exclusions. The execution can be speed up if the regular expression is only compiled once instead of every time in the hot loop. Signed-off-by: Benjamin Drung --- tarfilter | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tarfilter b/tarfilter index ab76683..517e01c 100755 --- a/tarfilter +++ b/tarfilter @@ -61,6 +61,7 @@ dpkg(1) for information on how these two options work in detail. exit() # same logic as in dpkg/src/filters.c/filter_should_skip() + prefix_prog = re.compile(r"^([^*?[\\]*).*") def filter_should_skip(member): skip = False if not args.filter: @@ -75,7 +76,7 @@ dpkg(1) for information on how these two options work in detail. for (t, r) in args.filter: if t != "path_include": continue - prefix = re.sub(r"^([^*?[\\]*).*", r"\1", r.pattern) + prefix = prefix_prog.sub(r"\1", r.pattern) prefix = prefix.rstrip("/") if member.name[1:].startswith(prefix): if member.name == "./usr/share/doc/doc-debian":