[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75
eric at webkit.org
eric at webkit.org
Thu Oct 29 20:47:55 UTC 2009
The following commit has been merged in the webkit-1.1 branch:
commit 1a630865f3e583cae2639e50184a730788be2796
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Oct 19 19:11:37 2009 +0000
2009-10-19 Jens Alfke <jens at mooseyard.com>
Reviewed by Darin Adler.
Optimize string upper/lowercasing
https://bugs.webkit.org/show_bug.cgi?id=30261
- Added AtomicString::upper() and lower()
- Further optimized StringImpl::lower()
- Removed StringImpl::isLower()
- Added QualifiedName::localNameUpper(), which is cached, thereby saving
thousands of upper() calls and string allocations.
* dom/Element.cpp:
(WebCore::Element::setAttribute): Call AtomicString::lower()
* dom/QualifiedName.cpp:
(WebCore::QualifiedName::localNameUpper): New method
* dom/QualifiedName.h: Added localNameUpper() method
* dom/StyledElement.cpp:
(WebCore::StyledElement::parseMappedAttribute): Call AtomicString::lower()
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::createElement): Call AtomicString::lower()
* html/HTMLElement.cpp:
(WebCore::HTMLElement::nodeName): Call localNameUpper()
* platform/text/AtomicString.cpp:
(WebCore::AtomicString::lower): New method
(WebCore::AtomicString::upper): New method
* platform/text/AtomicString.h: Added lower() and upper()
* platform/text/StringImpl.cpp: Removed isLower()
(WebCore::StringImpl::lower): Further optimization of initial loop
* platform/text/StringImpl.h: Removed isLower()
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49798 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 7e62c69..12b93a4 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,35 @@
+2009-10-19 Jens Alfke <jens at mooseyard.com>
+
+ Reviewed by Darin Adler.
+
+ Optimize string upper/lowercasing
+ https://bugs.webkit.org/show_bug.cgi?id=30261
+
+ - Added AtomicString::upper() and lower()
+ - Further optimized StringImpl::lower()
+ - Removed StringImpl::isLower()
+ - Added QualifiedName::localNameUpper(), which is cached, thereby saving
+ thousands of upper() calls and string allocations.
+
+ * dom/Element.cpp:
+ (WebCore::Element::setAttribute): Call AtomicString::lower()
+ * dom/QualifiedName.cpp:
+ (WebCore::QualifiedName::localNameUpper): New method
+ * dom/QualifiedName.h: Added localNameUpper() method
+ * dom/StyledElement.cpp:
+ (WebCore::StyledElement::parseMappedAttribute): Call AtomicString::lower()
+ * html/HTMLDocument.cpp:
+ (WebCore::HTMLDocument::createElement): Call AtomicString::lower()
+ * html/HTMLElement.cpp:
+ (WebCore::HTMLElement::nodeName): Call localNameUpper()
+ * platform/text/AtomicString.cpp:
+ (WebCore::AtomicString::lower): New method
+ (WebCore::AtomicString::upper): New method
+ * platform/text/AtomicString.h: Added lower() and upper()
+ * platform/text/StringImpl.cpp: Removed isLower()
+ (WebCore::StringImpl::lower): Further optimization of initial loop
+ * platform/text/StringImpl.h: Removed isLower()
+
2009-10-19 Nate Chapin <japhet at chromium.org>
Reviewed by Adam Barth.
diff --git a/WebCore/dom/Element.cpp b/WebCore/dom/Element.cpp
index 930a6a2..621c63a 100644
--- a/WebCore/dom/Element.cpp
+++ b/WebCore/dom/Element.cpp
@@ -516,7 +516,7 @@ void Element::setAttribute(const AtomicString& name, const AtomicString& value,
return;
}
- const AtomicString& localName = (shouldIgnoreAttributeCase(this) && !name.string().impl()->isLower()) ? AtomicString(name.string().lower()) : name;
+ const AtomicString& localName = shouldIgnoreAttributeCase(this) ? name.lower() : name;
// allocate attributemap if necessary
Attribute* old = attributes(false)->getAttributeItem(localName, false);
diff --git a/WebCore/dom/QualifiedName.cpp b/WebCore/dom/QualifiedName.cpp
index 607c846..2c5f39a 100644
--- a/WebCore/dom/QualifiedName.cpp
+++ b/WebCore/dom/QualifiedName.cpp
@@ -97,4 +97,11 @@ void QualifiedName::init()
}
}
+const AtomicString& QualifiedName::localNameUpper() const
+{
+ if (!m_impl->m_localNameUpper)
+ m_impl->m_localNameUpper = m_impl->m_localName.upper();
+ return m_impl->m_localNameUpper;
+}
+
}
diff --git a/WebCore/dom/QualifiedName.h b/WebCore/dom/QualifiedName.h
index 939927b..3b9f5c4 100644
--- a/WebCore/dom/QualifiedName.h
+++ b/WebCore/dom/QualifiedName.h
@@ -41,9 +41,10 @@ public:
return adoptRef(new QualifiedNameImpl(prefix, localName, namespaceURI));
}
- AtomicString m_prefix;
- AtomicString m_localName;
- AtomicString m_namespace;
+ const AtomicString m_prefix;
+ const AtomicString m_localName;
+ const AtomicString m_namespace;
+ mutable AtomicString m_localNameUpper;
private:
QualifiedNameImpl(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI)
@@ -76,6 +77,9 @@ public:
const AtomicString& localName() const { return m_impl->m_localName; }
const AtomicString& namespaceURI() const { return m_impl->m_namespace; }
+ // Uppercased localName, cached for efficiency
+ const AtomicString& localNameUpper() const;
+
String toString() const;
QualifiedNameImpl* impl() const { return m_impl; }
diff --git a/WebCore/dom/StyledElement.cpp b/WebCore/dom/StyledElement.cpp
index 5212380..46ce137 100644
--- a/WebCore/dom/StyledElement.cpp
+++ b/WebCore/dom/StyledElement.cpp
@@ -240,8 +240,8 @@ void StyledElement::parseMappedAttribute(MappedAttribute *attr)
if (namedAttrMap) {
if (attr->isNull())
namedAttrMap->setID(nullAtom);
- else if (document()->inCompatMode() && !attr->value().impl()->isLower())
- namedAttrMap->setID(AtomicString(attr->value().string().lower()));
+ else if (document()->inCompatMode())
+ namedAttrMap->setID(attr->value().lower());
else
namedAttrMap->setID(attr->value());
}
diff --git a/WebCore/html/HTMLDocument.cpp b/WebCore/html/HTMLDocument.cpp
index fd939c8..0d1cb19 100644
--- a/WebCore/html/HTMLDocument.cpp
+++ b/WebCore/html/HTMLDocument.cpp
@@ -307,8 +307,7 @@ PassRefPtr<Element> HTMLDocument::createElement(const AtomicString& name, Except
ec = INVALID_CHARACTER_ERR;
return 0;
}
- AtomicString lowerName = name.string().impl()->isLower() ? name : AtomicString(name.string().lower());
- return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, lowerName, xhtmlNamespaceURI), this, 0, false);
+ return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, name.lower(), xhtmlNamespaceURI), this, 0, false);
}
static void addItemToMap(HashCountedSet<AtomicStringImpl*>& map, const AtomicString& name)
diff --git a/WebCore/html/HTMLElement.cpp b/WebCore/html/HTMLElement.cpp
index 967a8e0..df3cb7d 100644
--- a/WebCore/html/HTMLElement.cpp
+++ b/WebCore/html/HTMLElement.cpp
@@ -67,7 +67,7 @@ String HTMLElement::nodeName() const
// the string on a hit in the hash.
// FIXME: We should have a way to detect XHTML elements and replace the hasPrefix() check with it.
if (document()->isHTMLDocument() && !tagQName().hasPrefix())
- return tagQName().localName().string().upper();
+ return tagQName().localNameUpper();
return Element::nodeName();
}
diff --git a/WebCore/platform/text/AtomicString.cpp b/WebCore/platform/text/AtomicString.cpp
index f7e3156..17d7832 100644
--- a/WebCore/platform/text/AtomicString.cpp
+++ b/WebCore/platform/text/AtomicString.cpp
@@ -228,6 +228,16 @@ void AtomicString::remove(StringImpl* r)
{
stringTable().remove(r);
}
+
+AtomicString AtomicString::lower() const
+{
+ // Note: This is a hot function in the Dromaeo benchmark.
+ StringImpl* impl = this->impl();
+ RefPtr<StringImpl> newImpl = impl->lower();
+ if (LIKELY(newImpl == impl))
+ return *this;
+ return AtomicString(newImpl);
+}
#if USE(JSC)
PassRefPtr<StringImpl> AtomicString::add(const JSC::Identifier& identifier)
diff --git a/WebCore/platform/text/AtomicString.h b/WebCore/platform/text/AtomicString.h
index 3307a2d..8805f4c 100644
--- a/WebCore/platform/text/AtomicString.h
+++ b/WebCore/platform/text/AtomicString.h
@@ -83,6 +83,9 @@ public:
bool endsWith(const String& s, bool caseSensitive = true) const
{ return m_string.endsWith(s, caseSensitive); }
+ AtomicString lower() const;
+ AtomicString upper() const { return AtomicString(impl()->upper()); }
+
int toInt(bool* ok = 0) const { return m_string.toInt(ok); }
double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); }
float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); }
diff --git a/WebCore/platform/text/StringImpl.cpp b/WebCore/platform/text/StringImpl.cpp
index c3f03de..5cf4ced 100644
--- a/WebCore/platform/text/StringImpl.cpp
+++ b/WebCore/platform/text/StringImpl.cpp
@@ -149,46 +149,26 @@ UChar32 StringImpl::characterStartingAt(unsigned i)
return 0;
}
-bool StringImpl::isLower()
-{
- // Do a faster loop for the case where all the characters are ASCII.
- bool allLower = true;
- UChar ored = 0;
- for (unsigned i = 0; i < m_length; i++) {
- UChar c = m_data[i];
- allLower = allLower && isASCIILower(c);
- ored |= c;
- }
- if (!(ored & ~0x7F))
- return allLower;
-
- // Do a slower check for cases that include non-ASCII characters.
- allLower = true;
- unsigned i = 0;
- while (i < m_length) {
- UChar32 character;
- U16_NEXT(m_data, i, m_length, character)
- allLower = allLower && Unicode::isLower(character);
- }
- return allLower;
-}
-
PassRefPtr<StringImpl> StringImpl::lower()
{
+ // Note: This is a hot function in the Dromaeo benchmark, specifically the
+ // no-op code path up through the first 'return' statement.
+
// First scan the string for uppercase and non-ASCII characters:
- int32_t length = m_length;
UChar ored = 0;
bool noUpper = true;
- for (int i = 0; i < length; i++) {
- UChar c = m_data[i];
- ored |= c;
- noUpper = noUpper && !isASCIIUpper(c);
+ const UChar *end = m_data + m_length;
+ for (const UChar* chp = m_data; chp != end; chp++) {
+ if (UNLIKELY(isASCIIUpper(*chp)))
+ noUpper = false;
+ ored |= *chp;
}
// Nothing to do if the string is all ASCII with no uppercase.
if (noUpper && !(ored & ~0x7F))
return this;
+ int32_t length = m_length;
UChar* data;
RefPtr<StringImpl> newImpl = createUninitialized(m_length, data);
diff --git a/WebCore/platform/text/StringImpl.h b/WebCore/platform/text/StringImpl.h
index ddf0df5..dac25b2 100644
--- a/WebCore/platform/text/StringImpl.h
+++ b/WebCore/platform/text/StringImpl.h
@@ -135,7 +135,6 @@ public:
double toDouble(bool* ok = 0);
float toFloat(bool* ok = 0);
- bool isLower();
PassRefPtr<StringImpl> lower();
PassRefPtr<StringImpl> upper();
PassRefPtr<StringImpl> secure(UChar aChar);
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list