Changeset 49798 in webkit
- Timestamp:
- Oct 19, 2009 12:11:37 PM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r49796 r49798 1 2009-10-19 Jens Alfke <jens@mooseyard.com> 2 3 Reviewed by Darin Adler. 4 5 Optimize string upper/lowercasing 6 https://bugs.webkit.org/show_bug.cgi?id=30261 7 8 - Added AtomicString::upper() and lower() 9 - Further optimized StringImpl::lower() 10 - Removed StringImpl::isLower() 11 - Added QualifiedName::localNameUpper(), which is cached, thereby saving 12 thousands of upper() calls and string allocations. 13 14 * dom/Element.cpp: 15 (WebCore::Element::setAttribute): Call AtomicString::lower() 16 * dom/QualifiedName.cpp: 17 (WebCore::QualifiedName::localNameUpper): New method 18 * dom/QualifiedName.h: Added localNameUpper() method 19 * dom/StyledElement.cpp: 20 (WebCore::StyledElement::parseMappedAttribute): Call AtomicString::lower() 21 * html/HTMLDocument.cpp: 22 (WebCore::HTMLDocument::createElement): Call AtomicString::lower() 23 * html/HTMLElement.cpp: 24 (WebCore::HTMLElement::nodeName): Call localNameUpper() 25 * platform/text/AtomicString.cpp: 26 (WebCore::AtomicString::lower): New method 27 (WebCore::AtomicString::upper): New method 28 * platform/text/AtomicString.h: Added lower() and upper() 29 * platform/text/StringImpl.cpp: Removed isLower() 30 (WebCore::StringImpl::lower): Further optimization of initial loop 31 * platform/text/StringImpl.h: Removed isLower() 32 1 33 2009-10-19 Nate Chapin <japhet@chromium.org> 2 34 -
trunk/WebCore/dom/Element.cpp
r49792 r49798 517 517 } 518 518 519 const AtomicString& localName = (shouldIgnoreAttributeCase(this) && !name.string().impl()->isLower()) ? AtomicString(name.string().lower()) : name;519 const AtomicString& localName = shouldIgnoreAttributeCase(this) ? name.lower() : name; 520 520 521 521 // allocate attributemap if necessary -
trunk/WebCore/dom/QualifiedName.cpp
r44147 r49798 98 98 } 99 99 100 const AtomicString& QualifiedName::localNameUpper() const 101 { 102 if (!m_impl->m_localNameUpper) 103 m_impl->m_localNameUpper = m_impl->m_localName.upper(); 104 return m_impl->m_localNameUpper; 100 105 } 106 107 } -
trunk/WebCore/dom/QualifiedName.h
r44147 r49798 42 42 } 43 43 44 AtomicString m_prefix; 45 AtomicString m_localName; 46 AtomicString m_namespace; 44 const AtomicString m_prefix; 45 const AtomicString m_localName; 46 const AtomicString m_namespace; 47 mutable AtomicString m_localNameUpper; 47 48 48 49 private: … … 76 77 const AtomicString& localName() const { return m_impl->m_localName; } 77 78 const AtomicString& namespaceURI() const { return m_impl->m_namespace; } 79 80 // Uppercased localName, cached for efficiency 81 const AtomicString& localNameUpper() const; 78 82 79 83 String toString() const; -
trunk/WebCore/dom/StyledElement.cpp
r47688 r49798 241 241 if (attr->isNull()) 242 242 namedAttrMap->setID(nullAtom); 243 else if (document()->inCompatMode() && !attr->value().impl()->isLower())244 namedAttrMap->setID( AtomicString(attr->value().string().lower()));243 else if (document()->inCompatMode()) 244 namedAttrMap->setID(attr->value().lower()); 245 245 else 246 246 namedAttrMap->setID(attr->value()); -
trunk/WebCore/html/HTMLDocument.cpp
r48430 r49798 308 308 return 0; 309 309 } 310 AtomicString lowerName = name.string().impl()->isLower() ? name : AtomicString(name.string().lower()); 311 return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, lowerName, xhtmlNamespaceURI), this, 0, false); 310 return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, name.lower(), xhtmlNamespaceURI), this, 0, false); 312 311 } 313 312 -
trunk/WebCore/html/HTMLElement.cpp
r48106 r49798 68 68 // FIXME: We should have a way to detect XHTML elements and replace the hasPrefix() check with it. 69 69 if (document()->isHTMLDocument() && !tagQName().hasPrefix()) 70 return tagQName().localName ().string().upper();70 return tagQName().localNameUpper(); 71 71 return Element::nodeName(); 72 72 } -
trunk/WebCore/platform/text/AtomicString.cpp
r49322 r49798 229 229 stringTable().remove(r); 230 230 } 231 232 AtomicString AtomicString::lower() const 233 { 234 // Note: This is a hot function in the Dromaeo benchmark. 235 StringImpl* impl = this->impl(); 236 RefPtr<StringImpl> newImpl = impl->lower(); 237 if (LIKELY(newImpl == impl)) 238 return *this; 239 return AtomicString(newImpl); 240 } 231 241 232 242 #if USE(JSC) -
trunk/WebCore/platform/text/AtomicString.h
r42245 r49798 84 84 { return m_string.endsWith(s, caseSensitive); } 85 85 86 AtomicString lower() const; 87 AtomicString upper() const { return AtomicString(impl()->upper()); } 88 86 89 int toInt(bool* ok = 0) const { return m_string.toInt(ok); } 87 90 double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); } -
trunk/WebCore/platform/text/StringImpl.cpp
r49403 r49798 150 150 } 151 151 152 bool StringImpl::isLower()153 {154 // Do a faster loop for the case where all the characters are ASCII.155 bool allLower = true;156 UChar ored = 0;157 for (unsigned i = 0; i < m_length; i++) {158 UChar c = m_data[i];159 allLower = allLower && isASCIILower(c);160 ored |= c;161 }162 if (!(ored & ~0x7F))163 return allLower;164 165 // Do a slower check for cases that include non-ASCII characters.166 allLower = true;167 unsigned i = 0;168 while (i < m_length) {169 UChar32 character;170 U16_NEXT(m_data, i, m_length, character)171 allLower = allLower && Unicode::isLower(character);172 }173 return allLower;174 }175 176 152 PassRefPtr<StringImpl> StringImpl::lower() 177 153 { 154 // Note: This is a hot function in the Dromaeo benchmark, specifically the 155 // no-op code path up through the first 'return' statement. 156 178 157 // First scan the string for uppercase and non-ASCII characters: 179 int32_t length = m_length;180 158 UChar ored = 0; 181 159 bool noUpper = true; 182 for (int i = 0; i < length; i++) { 183 UChar c = m_data[i]; 184 ored |= c; 185 noUpper = noUpper && !isASCIIUpper(c); 160 const UChar *end = m_data + m_length; 161 for (const UChar* chp = m_data; chp != end; chp++) { 162 if (UNLIKELY(isASCIIUpper(*chp))) 163 noUpper = false; 164 ored |= *chp; 186 165 } 187 166 … … 190 169 return this; 191 170 171 int32_t length = m_length; 192 172 UChar* data; 193 173 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); -
trunk/WebCore/platform/text/StringImpl.h
r49322 r49798 136 136 float toFloat(bool* ok = 0); 137 137 138 bool isLower();139 138 PassRefPtr<StringImpl> lower(); 140 139 PassRefPtr<StringImpl> upper();
Note: See TracChangeset
for help on using the changeset viewer.