From: Jan Beulich Date: Wed, 25 Jan 2017 14:10:21 +0000 (+0100) Subject: include: speed up compat header generation X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~2890 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=91f59d2041b0f2760da082827bcea57648845cc1;p=xen.git include: speed up compat header generation Recent additions to xlat.lst have apparently resulted in Python's garbage collection getting in the way: I would guess that so far it managed to re-use previously compiled regular expressions, but with the higher number of them now can't anymore (at least with default settings). Do the compilation explicitly. While at it, combine the two lists, and avoid using re.subn() when re.sub() suffices. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- diff --git a/xen/tools/compat-build-source.py b/xen/tools/compat-build-source.py index 55206e637a..595bc3ff58 100755 --- a/xen/tools/compat-build-source.py +++ b/xen/tools/compat-build-source.py @@ -12,19 +12,18 @@ pats = [ [ r"XEN_GUEST_HANDLE(_[0-9A-Fa-f]+)?", r"COMPAT_HANDLE" ], ]; -xlats = [] - xlatf = open('xlat.lst', 'r') for line in xlatf.readlines(): match = re.subn(r"^\s*\?\s+(\w*)\s.*", r"\1", line.rstrip()) if match[1]: - xlats.append(match[0]) + pats.append([ r"(struct|union)\s+(%s|xen_%s)\s+(\w)" % (match[0], match[0]), + r"\1 @KeeP@\2 \3" ]) xlatf.close() +for pat in pats: + pat[0] = re.compile(pat[0]) + for line in sys.stdin.readlines(): for pat in pats: - line = re.subn(pat[0], pat[1], line)[0] - for xlat in xlats: - line = re.subn(r"(struct|union)\s+(%s|xen_%s)\s+(\w)" % (xlat, xlat), - r"\1 @KeeP@\2 \3", line.rstrip())[0] + line = re.sub(pat[0], pat[1], line) print line.rstrip()