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 <jbeul...@suse.com>

--- 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()



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 <jbeul...@suse.com>

--- 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()
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

Reply via email to