| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 2 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 traversalSort(); | 169 traversalSort(); |
| 170 return; | 170 return; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool containsAttributeNodes = false; | 173 bool containsAttributeNodes = false; |
| 174 | 174 |
| 175 HeapVector<NodeSetVector> parentMatrix(nodeCount); | 175 HeapVector<NodeSetVector> parentMatrix(nodeCount); |
| 176 for (unsigned i = 0; i < nodeCount; ++i) { | 176 for (unsigned i = 0; i < nodeCount; ++i) { |
| 177 NodeSetVector& parentsVector = parentMatrix[i]; | 177 NodeSetVector& parentsVector = parentMatrix[i]; |
| 178 Node* n = m_nodes[i].get(); | 178 Node* n = m_nodes[i].get(); |
| 179 parentsVector.append(n); | 179 parentsVector.push_back(n); |
| 180 if (n->isAttributeNode()) { | 180 if (n->isAttributeNode()) { |
| 181 n = toAttr(n)->ownerElement(); | 181 n = toAttr(n)->ownerElement(); |
| 182 parentsVector.append(n); | 182 parentsVector.push_back(n); |
| 183 containsAttributeNodes = true; | 183 containsAttributeNodes = true; |
| 184 } | 184 } |
| 185 for (n = n->parentNode(); n; n = n->parentNode()) | 185 for (n = n->parentNode(); n; n = n->parentNode()) |
| 186 parentsVector.append(n); | 186 parentsVector.push_back(n); |
| 187 } | 187 } |
| 188 sortBlock(0, nodeCount, parentMatrix, containsAttributeNodes); | 188 sortBlock(0, nodeCount, parentMatrix, containsAttributeNodes); |
| 189 | 189 |
| 190 // It is not possible to just assign the result to m_nodes, because some | 190 // It is not possible to just assign the result to m_nodes, because some |
| 191 // nodes may get dereferenced and destroyed. | 191 // nodes may get dereferenced and destroyed. |
| 192 HeapVector<Member<Node>> sortedNodes; | 192 HeapVector<Member<Node>> sortedNodes; |
| 193 sortedNodes.reserveInitialCapacity(nodeCount); | 193 sortedNodes.reserveInitialCapacity(nodeCount); |
| 194 for (unsigned i = 0; i < nodeCount; ++i) | 194 for (unsigned i = 0; i < nodeCount; ++i) |
| 195 sortedNodes.append(parentMatrix[i][0]); | 195 sortedNodes.push_back(parentMatrix[i][0]); |
| 196 | 196 |
| 197 const_cast<HeapVector<Member<Node>>&>(m_nodes).swap(sortedNodes); | 197 const_cast<HeapVector<Member<Node>>&>(m_nodes).swap(sortedNodes); |
| 198 } | 198 } |
| 199 | 199 |
| 200 static Node* findRootNode(Node* node) { | 200 static Node* findRootNode(Node* node) { |
| 201 if (node->isAttributeNode()) | 201 if (node->isAttributeNode()) |
| 202 node = toAttr(node)->ownerElement(); | 202 node = toAttr(node)->ownerElement(); |
| 203 if (node->isConnected()) { | 203 if (node->isConnected()) { |
| 204 node = &node->document(); | 204 node = &node->document(); |
| 205 } else { | 205 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 220 nodes.add(node); | 220 nodes.add(node); |
| 221 if (node->isAttributeNode()) | 221 if (node->isAttributeNode()) |
| 222 containsAttributeNodes = true; | 222 containsAttributeNodes = true; |
| 223 } | 223 } |
| 224 | 224 |
| 225 HeapVector<Member<Node>> sortedNodes; | 225 HeapVector<Member<Node>> sortedNodes; |
| 226 sortedNodes.reserveInitialCapacity(nodeCount); | 226 sortedNodes.reserveInitialCapacity(nodeCount); |
| 227 | 227 |
| 228 for (Node& n : NodeTraversal::startsAt(*findRootNode(m_nodes.front()))) { | 228 for (Node& n : NodeTraversal::startsAt(*findRootNode(m_nodes.front()))) { |
| 229 if (nodes.contains(&n)) | 229 if (nodes.contains(&n)) |
| 230 sortedNodes.append(&n); | 230 sortedNodes.push_back(&n); |
| 231 | 231 |
| 232 if (!containsAttributeNodes || !n.isElementNode()) | 232 if (!containsAttributeNodes || !n.isElementNode()) |
| 233 continue; | 233 continue; |
| 234 | 234 |
| 235 Element* element = toElement(&n); | 235 Element* element = toElement(&n); |
| 236 AttributeCollection attributes = element->attributes(); | 236 AttributeCollection attributes = element->attributes(); |
| 237 for (auto& attribute : attributes) { | 237 for (auto& attribute : attributes) { |
| 238 Attr* attr = element->attrIfExists(attribute.name()); | 238 Attr* attr = element->attrIfExists(attribute.name()); |
| 239 if (attr && nodes.contains(attr)) | 239 if (attr && nodes.contains(attr)) |
| 240 sortedNodes.append(attr); | 240 sortedNodes.push_back(attr); |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 DCHECK_EQ(sortedNodes.size(), nodeCount); | 244 DCHECK_EQ(sortedNodes.size(), nodeCount); |
| 245 const_cast<HeapVector<Member<Node>>&>(m_nodes).swap(sortedNodes); | 245 const_cast<HeapVector<Member<Node>>&>(m_nodes).swap(sortedNodes); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void NodeSet::reverse() { | 248 void NodeSet::reverse() { |
| 249 if (m_nodes.isEmpty()) | 249 if (m_nodes.isEmpty()) |
| 250 return; | 250 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 270 | 270 |
| 271 Node* NodeSet::anyNode() const { | 271 Node* NodeSet::anyNode() const { |
| 272 if (isEmpty()) | 272 if (isEmpty()) |
| 273 return nullptr; | 273 return nullptr; |
| 274 | 274 |
| 275 return m_nodes.at(0).get(); | 275 return m_nodes.at(0).get(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace XPath | 278 } // namespace XPath |
| 279 } // namespace blink | 279 } // namespace blink |
| OLD | NEW |