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>
pull/1/head
Benjamin Drung 3 years ago committed by Johannes Schauer Marin Rodrigues
parent 5fd1ca62d9
commit 043ab3bbf0
Signed by: josch
GPG Key ID: F2CBA5C78FBD83E1

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

Loading…
Cancel
Save