Commit 46945bf4 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Optimize SelectorChecker's containsHTMLSpace() utility function

Avoid calling is8Bit() for every character in SelectorChecker's
containsHTMLSpace() by doing the check once at the beginning and then call a
templated containsHTMLSpaceTemplate() for the corresponding character type that
will iterate over the raw string array.

String::operator[] is not ideal here because:
- It checks if the String's StringImpl is non-null
- It does array bound checking
- It calls is8Bit() to access the right raw string array

The new implementation avoids doing these checks for every character in the
string being checked.

I see a 2.5% progression on cssquery-jquery's div[class~=dialog] subtest
(7152.80 -> 7331.60 +/- 0.5%):
http://dromaeo.com/?id=222400,222406

R=esprehn@chromium.org, eseidel@chromium.org

Review URL: https://codereview.chromium.org/307333004

git-svn-id: svn://svn.chromium.org/blink/trunk@175477 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 71b3dda2
...@@ -407,14 +407,22 @@ SelectorChecker::Match SelectorChecker::matchForShadowDistributed(const Element* ...@@ -407,14 +407,22 @@ SelectorChecker::Match SelectorChecker::matchForShadowDistributed(const Element*
return SelectorFailsLocally; return SelectorFailsLocally;
} }
static inline bool containsHTMLSpace(const AtomicString& string) template<typename CharType>
static inline bool containsHTMLSpaceTemplate(const CharType* string, unsigned length)
{ {
for (unsigned i = 0; i < string.length(); i++) for (unsigned i = 0; i < length; ++i)
if (isHTMLSpace<UChar>(string[i])) if (isHTMLSpace<CharType>(string[i]))
return true; return true;
return false; return false;
} }
static inline bool containsHTMLSpace(const AtomicString& string)
{
if (LIKELY(string.is8Bit()))
return containsHTMLSpaceTemplate<LChar>(string.characters8(), string.length());
return containsHTMLSpaceTemplate<UChar>(string.characters16(), string.length());
}
static bool attributeValueMatches(const Attribute& attributeItem, CSSSelector::Match match, const AtomicString& selectorValue, bool caseSensitive) static bool attributeValueMatches(const Attribute& attributeItem, CSSSelector::Match match, const AtomicString& selectorValue, bool caseSensitive)
{ {
const AtomicString& value = attributeItem.value(); const AtomicString& value = attributeItem.value();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment