| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 HTMLFormattingElementList::~HTMLFormattingElementList() | 44 HTMLFormattingElementList::~HTMLFormattingElementList() |
| 45 { | 45 { |
| 46 } | 46 } |
| 47 | 47 |
| 48 Element* HTMLFormattingElementList::closestElementInScopeWithName(const AtomicSt
ring& targetName) | 48 Element* HTMLFormattingElementList::closestElementInScopeWithName(const AtomicSt
ring& targetName) |
| 49 { | 49 { |
| 50 for (unsigned i = 1; i <= m_entries.size(); ++i) { | 50 for (unsigned i = 1; i <= m_entries.size(); ++i) { |
| 51 const Entry& entry = m_entries[m_entries.size() - i]; | 51 const Entry& entry = m_entries[m_entries.size() - i]; |
| 52 if (entry.isMarker()) | 52 if (entry.isMarker()) |
| 53 return 0; | 53 return nullptr; |
| 54 if (entry.stackItem()->matchesHTMLTag(targetName)) | 54 if (entry.stackItem()->matchesHTMLTag(targetName)) |
| 55 return entry.element(); | 55 return entry.element(); |
| 56 } | 56 } |
| 57 return 0; | 57 return nullptr; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool HTMLFormattingElementList::contains(Element* element) | 60 bool HTMLFormattingElementList::contains(Element* element) |
| 61 { | 61 { |
| 62 return !!find(element); | 62 return !!find(element); |
| 63 } | 63 } |
| 64 | 64 |
| 65 HTMLFormattingElementList::Entry* HTMLFormattingElementList::find(Element* eleme
nt) | 65 HTMLFormattingElementList::Entry* HTMLFormattingElementList::find(Element* eleme
nt) |
| 66 { | 66 { |
| 67 size_t index = m_entries.reverseFind(element); | 67 size_t index = m_entries.reverseFind(element); |
| 68 if (index != kNotFound) { | 68 if (index != kNotFound) { |
| 69 // This is somewhat of a hack, and is why this method can't be const. | 69 // This is somewhat of a hack, and is why this method can't be const. |
| 70 return &m_entries[index]; | 70 return &m_entries[index]; |
| 71 } | 71 } |
| 72 return 0; | 72 return nullptr; |
| 73 } | 73 } |
| 74 | 74 |
| 75 HTMLFormattingElementList::Bookmark HTMLFormattingElementList::bookmarkFor(Eleme
nt* element) | 75 HTMLFormattingElementList::Bookmark HTMLFormattingElementList::bookmarkFor(Eleme
nt* element) |
| 76 { | 76 { |
| 77 size_t index = m_entries.reverseFind(element); | 77 size_t index = m_entries.reverseFind(element); |
| 78 ASSERT(index != kNotFound); | 78 ASSERT(index != kNotFound); |
| 79 return Bookmark(&at(index)); | 79 return Bookmark(&at(index)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void HTMLFormattingElementList::swapTo(Element* oldElement, PassRefPtrWillBeRawP
tr<HTMLStackItem> newItem, const Bookmark& bookmark) | 82 void HTMLFormattingElementList::swapTo(Element* oldElement, PassRefPtrWillBeRawP
tr<HTMLStackItem> newItem, const Bookmark& bookmark) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 { | 116 { |
| 117 // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#
clear-the-list-of-active-formatting-elements-up-to-the-last-marker | 117 // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#
clear-the-list-of-active-formatting-elements-up-to-the-last-marker |
| 118 while (m_entries.size()) { | 118 while (m_entries.size()) { |
| 119 bool shouldStop = m_entries.last().isMarker(); | 119 bool shouldStop = m_entries.last().isMarker(); |
| 120 m_entries.removeLast(); | 120 m_entries.removeLast(); |
| 121 if (shouldStop) | 121 if (shouldStop) |
| 122 break; | 122 break; |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 void HTMLFormattingElementList::tryToEnsureNoahsArkConditionQuickly(HTMLStackIte
m* newItem, WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem> >& remainingCandi
dates) | 126 void HTMLFormattingElementList::tryToEnsureNoahsArkConditionQuickly(HTMLStackIte
m* newItem, WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem>>& remainingCandid
ates) |
| 127 { | 127 { |
| 128 ASSERT(remainingCandidates.isEmpty()); | 128 ASSERT(remainingCandidates.isEmpty()); |
| 129 | 129 |
| 130 if (m_entries.size() < kNoahsArkCapacity) | 130 if (m_entries.size() < kNoahsArkCapacity) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 // Use a vector with inline capacity to avoid a malloc in the common case | 133 // Use a vector with inline capacity to avoid a malloc in the common case |
| 134 // of a quickly ensuring the condition. | 134 // of a quickly ensuring the condition. |
| 135 WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem>, 10> candidates; | 135 WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem>, 10> candidates; |
| 136 | 136 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 153 } | 153 } |
| 154 | 154 |
| 155 if (candidates.size() < kNoahsArkCapacity) | 155 if (candidates.size() < kNoahsArkCapacity) |
| 156 return; // There's room for the new element in the ark. There's no need
to copy out the remainingCandidates. | 156 return; // There's room for the new element in the ark. There's no need
to copy out the remainingCandidates. |
| 157 | 157 |
| 158 remainingCandidates.appendVector(candidates); | 158 remainingCandidates.appendVector(candidates); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void HTMLFormattingElementList::ensureNoahsArkCondition(HTMLStackItem* newItem) | 161 void HTMLFormattingElementList::ensureNoahsArkCondition(HTMLStackItem* newItem) |
| 162 { | 162 { |
| 163 WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem> > candidates; | 163 WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem>> candidates; |
| 164 tryToEnsureNoahsArkConditionQuickly(newItem, candidates); | 164 tryToEnsureNoahsArkConditionQuickly(newItem, candidates); |
| 165 if (candidates.isEmpty()) | 165 if (candidates.isEmpty()) |
| 166 return; | 166 return; |
| 167 | 167 |
| 168 // We pre-allocate and re-use this second vector to save one malloc per | 168 // We pre-allocate and re-use this second vector to save one malloc per |
| 169 // attribute that we verify. | 169 // attribute that we verify. |
| 170 WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem> > remainingCandidates; | 170 WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem>> remainingCandidates; |
| 171 remainingCandidates.reserveInitialCapacity(candidates.size()); | 171 remainingCandidates.reserveInitialCapacity(candidates.size()); |
| 172 | 172 |
| 173 const Vector<Attribute>& attributes = newItem->attributes(); | 173 const Vector<Attribute>& attributes = newItem->attributes(); |
| 174 for (size_t i = 0; i < attributes.size(); ++i) { | 174 for (size_t i = 0; i < attributes.size(); ++i) { |
| 175 const Attribute& attribute = attributes[i]; | 175 const Attribute& attribute = attributes[i]; |
| 176 | 176 |
| 177 for (size_t j = 0; j < candidates.size(); ++j) { | 177 for (size_t j = 0; j < candidates.size(); ++j) { |
| 178 HTMLStackItem* candidate = candidates[j]; | 178 HTMLStackItem* candidate = candidates[j]; |
| 179 | 179 |
| 180 // These properties should already have been checked by tryToEnsureN
oahsArkConditionQuickly. | 180 // These properties should already have been checked by tryToEnsureN
oahsArkConditionQuickly. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 209 if (entry.isMarker()) | 209 if (entry.isMarker()) |
| 210 fprintf(stderr, "marker\n"); | 210 fprintf(stderr, "marker\n"); |
| 211 else | 211 else |
| 212 entry.element()->showNode(); | 212 entry.element()->showNode(); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 #endif | 216 #endif |
| 217 | 217 |
| 218 } | 218 } |
| OLD | NEW |