Changeset 52899 in webkit
- Timestamp:
- Jan 6, 2010 8:45:10 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r52898 r52899 1 2010-01-06 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Use a static HashMap for HTMLElement::tagPriority(). 6 https://bugs.webkit.org/show_bug.cgi?id=33269 7 8 The prior code compares AtomicStringImpl pointers 18 times at 9 worst. This change avoids it. 10 11 No new tests because this is just a refactoring. 12 13 * html/HTMLElement.cpp: 14 (WebCore::Empty1IntHashTraits): A HashTraits to return 1 as the empty value. 15 (WebCore::initializeTagPriorityMap): Initialization of a static HashMap. 16 (WebCore::HTMLElement::tagPriority): Use the static HashMap created by initializeTagPriorityMap(). 17 * html/HTMLElement.h: 18 (WebCore::HTMLElement::HTMLElement): Add an assertion about non-null localName(). 19 1 20 2010-01-06 Mike Belshe <mike@belshe.com> 2 21 -
trunk/WebCore/html/HTMLElement.cpp
r52846 r52899 83 83 } 84 84 85 struct Empty1IntHashTraits : HashTraits<int> { 86 static const bool emptyValueIsZero = false; 87 static int emptyValue() { return 1; } 88 }; 89 typedef HashMap<AtomicStringImpl*, int, DefaultHash<AtomicStringImpl*>::Hash, HashTraits<AtomicStringImpl*>, Empty1IntHashTraits> TagPriorityMap; 90 91 static const TagPriorityMap* createTagPriorityMap() 92 { 93 TagPriorityMap* map = new TagPriorityMap; 94 95 map->add(wbrTag.localName().impl(), 0); 96 97 map->add(addressTag.localName().impl(), 3); 98 map->add(ddTag.localName().impl(), 3); 99 map->add(dtTag.localName().impl(), 3); 100 map->add(noscriptTag.localName().impl(), 3); 101 map->add(rpTag.localName().impl(), 3); 102 map->add(rtTag.localName().impl(), 3); 103 104 // 5 is same as <div>'s priority. 105 map->add(articleTag.localName().impl(), 5); 106 map->add(asideTag.localName().impl(), 5); 107 map->add(centerTag.localName().impl(), 5); 108 map->add(footerTag.localName().impl(), 5); 109 map->add(headerTag.localName().impl(), 5); 110 map->add(nobrTag.localName().impl(), 5); 111 map->add(rubyTag.localName().impl(), 5); 112 map->add(navTag.localName().impl(), 5); 113 map->add(sectionTag.localName().impl(), 5); 114 115 map->add(noembedTag.localName().impl(), 10); 116 map->add(noframesTag.localName().impl(), 10); 117 118 // TagPriorityMap returns 1 for unregistered tags. It's same as <span>. 119 // This way custom tag name elements will behave like inline spans. 120 return map; 121 } 122 85 123 int HTMLElement::tagPriority() const 86 124 { 87 if (hasLocalName(wbrTag)) 88 return 0; 89 if (hasLocalName(addressTag) || hasLocalName(ddTag) || hasLocalName(dtTag) || hasLocalName(noscriptTag) || hasLocalName(rpTag) || hasLocalName(rtTag)) 90 return 3; 91 if (hasLocalName(articleTag) || hasLocalName(asideTag) || hasLocalName(centerTag) || hasLocalName(footerTag) || hasLocalName(headerTag) || hasLocalName(nobrTag) || hasLocalName(rubyTag) || hasLocalName(navTag) || hasLocalName(sectionTag)) 92 return 5; // Same as <div>. 93 if (hasLocalName(noembedTag) || hasLocalName(noframesTag)) 94 return 10; 95 96 // Same values as <span>. This way custom tag name elements will behave like inline spans. 97 return 1; 125 static const TagPriorityMap* tagPriorityMap = createTagPriorityMap(); 126 return tagPriorityMap->get(localName().impl()); 98 127 } 99 128 -
trunk/WebCore/html/HTMLElement.h
r48106 r52899 117 117 : StyledElement(tagName, document, type) 118 118 { 119 ASSERT(tagName.localName().impl()); 119 120 } 120 121
Note: See TracChangeset
for help on using the changeset viewer.