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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 return 0; | 72 return 0; |
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, PassRefPtr<HTMLStack
Item> newItem, const Bookmark& bookmark) | 82 void HTMLFormattingElementList::swapTo(Element* oldElement, PassRefPtrWillBeRawP
tr<HTMLStackItem> newItem, const Bookmark& bookmark) |
83 { | 83 { |
84 ASSERT(contains(oldElement)); | 84 ASSERT(contains(oldElement)); |
85 ASSERT(!contains(newItem->element())); | 85 ASSERT(!contains(newItem->element())); |
86 if (!bookmark.hasBeenMoved()) { | 86 if (!bookmark.hasBeenMoved()) { |
87 ASSERT(bookmark.mark()->element() == oldElement); | 87 ASSERT(bookmark.mark()->element() == oldElement); |
88 bookmark.mark()->replaceElement(newItem); | 88 bookmark.mark()->replaceElement(newItem); |
89 return; | 89 return; |
90 } | 90 } |
91 size_t index = bookmark.mark() - first(); | 91 size_t index = bookmark.mark() - first(); |
92 ASSERT_WITH_SECURITY_IMPLICATION(index < size()); | 92 ASSERT_WITH_SECURITY_IMPLICATION(index < size()); |
93 m_entries.insert(index + 1, newItem); | 93 m_entries.insert(index + 1, newItem); |
94 remove(oldElement); | 94 remove(oldElement); |
95 } | 95 } |
96 | 96 |
97 void HTMLFormattingElementList::append(PassRefPtr<HTMLStackItem> item) | 97 void HTMLFormattingElementList::append(PassRefPtrWillBeRawPtr<HTMLStackItem> ite
m) |
98 { | 98 { |
99 ensureNoahsArkCondition(item.get()); | 99 ensureNoahsArkCondition(item.get()); |
100 m_entries.append(item); | 100 m_entries.append(item); |
101 } | 101 } |
102 | 102 |
103 void HTMLFormattingElementList::remove(Element* element) | 103 void HTMLFormattingElementList::remove(Element* element) |
104 { | 104 { |
105 size_t index = m_entries.reverseFind(element); | 105 size_t index = m_entries.reverseFind(element); |
106 if (index != kNotFound) | 106 if (index != kNotFound) |
107 m_entries.remove(index); | 107 m_entries.remove(index); |
108 } | 108 } |
109 | 109 |
110 void HTMLFormattingElementList::appendMarker() | 110 void HTMLFormattingElementList::appendMarker() |
111 { | 111 { |
112 m_entries.append(Entry::MarkerEntry); | 112 m_entries.append(Entry::MarkerEntry); |
113 } | 113 } |
114 | 114 |
115 void HTMLFormattingElementList::clearToLastMarker() | 115 void HTMLFormattingElementList::clearToLastMarker() |
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, Vector<HTMLStackItem*>& remainingCandidates) | 126 void HTMLFormattingElementList::tryToEnsureNoahsArkConditionQuickly(HTMLStackIte
m* newItem, WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem> >& remainingCandi
dates) |
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 Vector<HTMLStackItem*, 10> candidates; | 135 WillBeHeapVector<RawPtrWillBeMember<HTMLStackItem>, 10> candidates; |
136 | 136 |
137 size_t newItemAttributeCount = newItem->attributes().size(); | 137 size_t newItemAttributeCount = newItem->attributes().size(); |
138 | 138 |
139 for (size_t i = m_entries.size(); i; ) { | 139 for (size_t i = m_entries.size(); i; ) { |
140 --i; | 140 --i; |
141 Entry& entry = m_entries[i]; | 141 Entry& entry = m_entries[i]; |
142 if (entry.isMarker()) | 142 if (entry.isMarker()) |
143 break; | 143 break; |
144 | 144 |
145 // Quickly reject obviously non-matching candidates. | 145 // Quickly reject obviously non-matching candidates. |
146 HTMLStackItem* candidate = entry.stackItem().get(); | 146 HTMLStackItem* candidate = entry.stackItem().get(); |
147 if (newItem->localName() != candidate->localName() || newItem->namespace
URI() != candidate->namespaceURI()) | 147 if (newItem->localName() != candidate->localName() || newItem->namespace
URI() != candidate->namespaceURI()) |
148 continue; | 148 continue; |
149 if (candidate->attributes().size() != newItemAttributeCount) | 149 if (candidate->attributes().size() != newItemAttributeCount) |
150 continue; | 150 continue; |
151 | 151 |
152 candidates.append(candidate); | 152 candidates.append(candidate); |
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 Vector<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 Vector<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 |