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 <benjamin.drung@cloud.ionos.com>
This commit is contained in:
Benjamin Drung 2021-02-18 21:14:11 +01:00 committed by Johannes Schauer Marin Rodrigues
parent 5fd1ca62d9
commit 043ab3bbf0
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -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":