From 3c31d970c01a4130165dd1a178276c280b55b27a Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Mon, 28 Nov 2016 10:13:08 +1100 Subject: [PATCH] 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 --HG-- extra : source : 76731753ce13d2d9e427935112b02df2781cd44a --- layout/reftests/w3c-css/import-tests.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/layout/reftests/w3c-css/import-tests.py b/layout/reftests/w3c-css/import-tests.py index 1a631e2bece3..7bc1019f29c2 100755 --- a/layout/reftests/w3c-css/import-tests.py +++ b/layout/reftests/w3c-css/import-tests.py @@ -50,6 +50,9 @@ gPrefixedProperties = [ "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)" @@ -134,7 +137,7 @@ def copy_file(test, srcfile, destname, isSupportFile=False): 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 @@ -242,8 +245,8 @@ AHEM_DECL_XML = """ """ -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:] @@ -260,9 +263,7 @@ def copy_and_prefix(test, aSourceFileName, aDestFileName, aProps, isSupportFile= 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()