Skip to content

Commit d1482c9

Browse files
committed
<https://webkit.org/b/119850> Speed up test importing by doing all the regex matching in a single pass
Reviewed by Dirk Pranke. This is a port from Blink of https://src.chromium.org/viewvc/blink?revision=155647&view=revision originally by Dirk Pranke. From the original commit: This gives something like a 15x speedup over compiling and matching one property at a time and doing multiple passes over the file. * Scripts/webkitpy/w3c/test_converter.py: (W3CTestConverter.__init__): (W3CTestConverter.convert_prefixed_properties): (W3CTestConverter.add_webkit_prefix_to_unprefixed_properties): Canonical link: https://commits.webkit.org/137805@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154126 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent b6cf91a commit d1482c9

2 files changed

Lines changed: 41 additions & 16 deletions

File tree

Tools/ChangeLog

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
2013-08-15 Bem Jones-Bey <bjonesbe@adobe.com>
2+
3+
<https://webkit.org/b/119850> Speed up test importing by doing all the regex matching in a single pass
4+
5+
Reviewed by Dirk Pranke.
6+
7+
This is a port from Blink of
8+
https://src.chromium.org/viewvc/blink?revision=155647&view=revision
9+
originally by Dirk Pranke.
10+
11+
From the original commit:
12+
13+
This gives something like a 15x speedup over compiling and matching
14+
one property at a time and doing multiple passes over the file.
15+
16+
* Scripts/webkitpy/w3c/test_converter.py:
17+
(W3CTestConverter.__init__):
18+
(W3CTestConverter.convert_prefixed_properties):
19+
(W3CTestConverter.add_webkit_prefix_to_unprefixed_properties):
20+
121
2013-08-15 Dan Bernstein <mitz@apple.com>
222

323
<https://webkit.org/b/119856> Improve extract-localizable-strings messages

Tools/Scripts/webkitpy/w3c/test_converter.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def __init__(self):
5151

5252
self.prefixed_properties = self.read_webkit_prefixed_css_property_list()
5353

54+
prop_regex = '([\s{]|^)(' + "|".join(prop.replace('-webkit-', '') for prop in self.prefixed_properties) + ')(\s+:|:)'
55+
self.prop_re = re.compile(prop_regex)
56+
5457
def path_from_webkit_root(self, *comps):
5558
return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps))
5659

@@ -157,35 +160,37 @@ def convert_prefixed_properties(self, doc, filename):
157160

158161
# Rewrite tag only if changes were made.
159162
if updated_style_text[0]:
160-
converted_properties.extend(updated_style_text[0])
163+
converted_properties.extend(list(updated_style_text[0]))
161164

162165
new_tag = Tag(doc, tag.name, tag.attrs)
163166
new_tag.insert(0, updated_style_text[1])
164167

165168
self.replace_tag(tag, new_tag)
166169

170+
# FIXME: Doing the replace in the parsed document and then writing it back out
171+
# is normalizing the HTML, which may in fact alter the intent of some tests.
172+
# We should probably either just do basic string-replaces, or have some other
173+
# way of flagging tests that are sensitive to being rewritten.
174+
# https://bugs.webkit.org/show_bug.cgi?id=119159
175+
167176
return (converted_properties, doc.prettify())
168177

169178
def add_webkit_prefix_to_unprefixed_properties(self, text, filename):
170179
""" Searches |text| for instances of properties requiring the -webkit- prefix and adds the prefix to them.
171180
172181
Returns the list of converted properties and the modified text."""
173182

174-
converted_properties = []
175-
176-
for raw_property in self.prefixed_properties:
177-
# FIXME: add in both the prefixed and unprefixed versions, rather than just replacing them?
178-
# That might allow the imported test to work in other browsers more easily.
179-
180-
# Look for the various ways it might be in the CSS
181-
# Match the the property preceded by either whitespace or left curly brace
182-
# or at the beginning of the string (for inline style attribute)
183-
pattern = '([\s{]|^)' + raw_property + '(\s+:|:)'
184-
if re.search(pattern, text):
185-
replacement_property = '-webkit-%s' % raw_property
186-
_log.info('converting %s -> %s' % (raw_property, replacement_property))
187-
converted_properties.append(replacement_property)
188-
text = re.sub(pattern, replacement_property + ':', text)
183+
converted_properties = set()
184+
text_chunks = []
185+
cur_pos = 0
186+
for m in self.prop_re.finditer(text):
187+
text_chunks.extend([text[cur_pos:m.start()], m.group(1), '-webkit-', m.group(2), m.group(3)])
188+
converted_properties.add(m.group(2))
189+
cur_pos = m.end()
190+
text_chunks.append(text[cur_pos:])
191+
192+
for prop in converted_properties:
193+
_log.info(' converting %s', prop)
189194

190195
# FIXME: Handle the JS versions of these properties and GetComputedStyle, too.
191196
return (converted_properties, text)

0 commit comments

Comments
 (0)