Bug 1413111 - Use nsTSubstring::Split in nsCSSRuleProcessor::LangPseudoMatches instead of manually go through with FindChar. draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 01 Nov 2017 10:19:56 +0900
changeset 689854 5b0b1f06c2384d18841073358aab75d37648f1f4
parent 689081 083a9c84fbd09a6ff9bfecabbf773650842fe1c0
child 689859 e16b59febff8a6013a0f34b3585a4e6ddcfc3082
push id87119
push userbmo:mh+mozilla@glandium.org
push dateWed, 01 Nov 2017 01:39:40 +0000
bugs1413111
milestone58.0a1
Bug 1413111 - Use nsTSubstring::Split in nsCSSRuleProcessor::LangPseudoMatches instead of manually go through with FindChar.
layout/style/nsCSSRuleProcessor.cpp
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -1679,32 +1679,22 @@ nsCSSRuleProcessor::LangPseudoMatches(co
   // is missing as well from the preferences.
   // The content language can be a comma-separated list of
   // language codes.
   nsAutoString language;
   aDocument->GetContentLanguage(language);
 
   nsDependentString langString(aString);
   language.StripWhitespace();
-  int32_t begin = 0;
-  int32_t len = language.Length();
-  while (begin < len) {
-    int32_t end = language.FindChar(char16_t(','), begin);
-    if (end == kNotFound) {
-      end = len;
-    }
-    if (nsStyleUtil::DashMatchCompare(Substring(language, begin, end - begin),
+  for (auto const& lang : language.Split(char16_t(','))) {
+    if (nsStyleUtil::DashMatchCompare(lang,
                                       langString,
                                       nsASCIICaseInsensitiveStringComparator())) {
       return true;
     }
-    begin = end + 1;
-  }
-  if (begin < len) {
-    return true;
   }
   return false;
 }
 
 /* static */ bool
 nsCSSRuleProcessor::StringPseudoMatches(const mozilla::dom::Element* aElement,
                                         CSSPseudoClassType aPseudo,
                                         const char16_t* aString,