Commit 40dc7d65 authored by fs's avatar fs Committed by Commit bot

Don't use substring() for a simple prefix match

The language code match in SVGTests::isValid() uses String::substring()
to limit the match to the primary language subtag. In the case where the
defaultLanguage() only contains the/a primary language subtag, this will
not require a copy, but otherwise it would.

Using startsWith() and a length-check guarantees that no copies will be
made. (A valid primary language subtag is always 2 letter long, so
checking only for length == 2 should be enough, although previously the
code could theoretically match a 1 letter, or even a zero-length tag.)

Review-Url: https://codereview.chromium.org/2284273002
Cr-Commit-Position: refs/heads/master@{#415255}
parent 02da78d1
......@@ -51,15 +51,12 @@ bool SVGTests::isValid() const
if (m_systemLanguage->isSpecified()) {
bool matchFound = false;
const Vector<String>& systemLanguage = m_systemLanguage->value()->values();
for (const auto& value : systemLanguage) {
if (value == defaultLanguage().getString().substring(0, 2)) {
for (const auto& value : m_systemLanguage->value()->values()) {
if (value.length() == 2 && defaultLanguage().startsWith(value)) {
matchFound = true;
break;
}
}
if (!matchFound)
return false;
}
......
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