include: speed up compat header generation
authorJan Beulich <jbeulich@suse.com>
Wed, 25 Jan 2017 14:10:21 +0000 (15:10 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 25 Jan 2017 14:10:21 +0000 (15:10 +0100)
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 <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/tools/compat-build-source.py

index 55206e637a1f8de12a697ca89cc5fa42a760c538..595bc3ff58be11cf5dc07a1812db2ff2e3f0d549 100755 (executable)
@@ -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()