Bug 1258916 part 9 - Optimize re.sub usage in import script. r=dbaron draft
authorXidorn Quan <me@upsuper.org>
Mon, 14 Nov 2016 12:20:38 +1100
changeset 439570 2631eb9f7f5e410e72f6c684075975fa4e16d534
parent 439569 b290f0a071f3440bea0409c1cd1787e292267da3
child 439571 41ef09592989d46b93bc070fb218afb59a70dde5
child 440702 b6e98fbdeb3c97d8ef69dce81fd75db0fd9ab3db
child 441092 8881eb3eac5728056c45c2e9b5851f2e2f1945ec
push id36052
push userxquan@mozilla.com
push dateWed, 16 Nov 2016 10:08:48 +0000
reviewersdbaron
bugs1258916
milestone53.0a1
Bug 1258916 part 9 - Optimize re.sub usage in import script. r=dbaron This reduces the time to import by ~30% with css-writing-modes included. MozReview-Commit-ID: JsnkRfTFnp6
layout/reftests/w3c-css/import-tests.py
--- a/layout/reftests/w3c-css/import-tests.py
+++ b/layout/reftests/w3c-css/import-tests.py
@@ -45,16 +45,19 @@ gPrefixedProperties = [
     "column-rule-color",
     "column-rule-style",
     "column-rule-width",
     "columns",
     "column-span",
     "column-width"
 ]
 
+gPrefixRegexp = re.compile(
+    r"([^-#]|^)(" + r"|".join(gPrefixedProperties) + r")\b")
+
 # Map of about:config prefs that need toggling, for a given test subdirectory.
 # Entries should look like:
 #  "$SUBDIR_NAME": "pref($PREF_NAME, $PREF_VALUE)"
 #
 # For example, when "@supports" was behind a pref, gDefaultPreferences had:
 #  "css3-conditional": "pref(layout.css.supports-rule.enabled,true)"
 gDefaultPreferences = {
 }
@@ -129,17 +132,17 @@ def copy_file(test, srcfile, destname, i
     gLog.write("Importing " + to_unix_path_sep(logname) +
                " to " + to_unix_path_sep(destname) + "\n")
     destfile = os.path.join(gDestPath, destname)
     destdir = os.path.dirname(destfile)
     if not os.path.exists(destdir):
         os.makedirs(destdir)
     if os.path.exists(destfile):
         raise StandardError("file " + destfile + " already exists")
-    copy_and_prefix(test, srcfile, destfile, gPrefixedProperties, isSupportFile)
+    copy_and_prefix(test, srcfile, destfile, isSupportFile)
 
 def copy_support_files(test, dirname):
     global gSrcPath
     if dirname in support_dirs_mapped:
         return
     support_dirs_mapped.add(dirname)
     support_dir = os.path.join(dirname, "support")
     if not os.path.exists(support_dir):
@@ -237,37 +240,35 @@ AHEM_DECL_HTML = """<style type="text/cs
 """ + AHEM_DECL_CONTENT + """
 </style>
 """
 AHEM_DECL_XML = """<style type="text/css"><![CDATA[
 """ + AHEM_DECL_CONTENT + """
 ]]></style>
 """
 
-def copy_and_prefix(test, aSourceFileName, aDestFileName, aProps, isSupportFile=False):
-    global gTestFlags
+def copy_and_prefix(test, aSourceFileName, aDestFileName, isSupportFile=False):
+    global gTestFlags, gPrefixRegexp
     newFile = open(aDestFileName, 'wb')
     unPrefixedFile = open(aSourceFileName, 'rb')
     testName = aDestFileName[len(gDestPath)+1:]
     ahemFontAdded = False
     for line in unPrefixedFile:
         replacementLine = line
         searchRegex = "\s*<style\s*"
 
         if not isSupportFile and not ahemFontAdded and 'ahem' in gTestFlags[test] and re.search(searchRegex, line):
             # First put our ahem font declation before the first <style>
             # element
             template = AHEM_DECL_HTML if is_html(aDestFileName) else AHEM_DECL_XML
             ahemPath = os.path.relpath(AHEM_FONT_PATH, os.path.dirname(aDestFileName))
             newFile.write(template.format(to_unix_path_sep(ahemPath)))
             ahemFontAdded = True
 
-        for prop in aProps:
-            replacementLine = re.sub(r"([^-#]|^)" + prop + r"\b", r"\1-moz-" + prop, replacementLine)
-
+        replacementLine = gPrefixRegexp.sub(r"\1-moz-\2", replacementLine)
         newFile.write(replacementLine)
 
     newFile.close()
     unPrefixedFile.close()
 
 def read_options():
     global gArgs, gOptions
     op = OptionParser()