Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: Source/core/dom/ContainerNode.h

Issue 15871005: Avoid N^2 walk placing renderers when building the render tree (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Reversing the snapshotting logic to fix a bug, and updating test expectations. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 ASSERT(!nodes.size()); 277 ASSERT(!nodes.size());
278 for (Node* child = node->firstChild(); child; child = child->nextSibling()) 278 for (Node* child = node->firstChild(); child; child = child->nextSibling())
279 nodes.append(child); 279 nodes.append(child);
280 } 280 }
281 281
282 class ChildNodesLazySnapshot { 282 class ChildNodesLazySnapshot {
283 WTF_MAKE_NONCOPYABLE(ChildNodesLazySnapshot); 283 WTF_MAKE_NONCOPYABLE(ChildNodesLazySnapshot);
284 WTF_MAKE_FAST_ALLOCATED; 284 WTF_MAKE_FAST_ALLOCATED;
285 public: 285 public:
286 explicit ChildNodesLazySnapshot(Node* parentNode) 286 explicit ChildNodesLazySnapshot(Node* parentNode)
287 : m_currentNode(parentNode->firstChild()) 287 : m_currentNode(parentNode->lastChild())
288 , m_currentIndex(0) 288 , m_currentIndex(0)
289 { 289 {
290 m_nextSnapshot = latestSnapshot; 290 m_nextSnapshot = latestSnapshot;
291 latestSnapshot = this; 291 latestSnapshot = this;
292 } 292 }
293 293
294 ~ChildNodesLazySnapshot() 294 ~ChildNodesLazySnapshot()
295 { 295 {
296 latestSnapshot = m_nextSnapshot; 296 latestSnapshot = m_nextSnapshot;
297 } 297 }
298 298
299 // Returns 0 if there is no next Node. 299 // Returns 0 if there is no next Node.
esprehn 2013/06/05 00:12:26 is no previous node?
300 PassRefPtr<Node> nextNode() 300 PassRefPtr<Node> previousNode()
301 { 301 {
302 if (LIKELY(!hasSnapshot())) { 302 if (LIKELY(!hasSnapshot())) {
303 RefPtr<Node> node = m_currentNode; 303 RefPtr<Node> node = m_currentNode;
304 if (node) 304 if (node)
305 m_currentNode = node->nextSibling(); 305 m_currentNode = node->previousSibling();
306 return node.release(); 306 return node.release();
307 } 307 }
308 Vector<RefPtr<Node> >& nodeVector = *m_childNodes; 308 Vector<RefPtr<Node> >& nodeVector = *m_childNodes;
309 if (m_currentIndex >= nodeVector.size()) 309 if (m_currentIndex >= nodeVector.size())
310 return 0; 310 return 0;
311 return nodeVector[m_currentIndex++]; 311 return nodeVector[m_currentIndex++];
312 } 312 }
313 313
314 void takeSnapshot() 314 void takeSnapshot()
315 { 315 {
316 if (hasSnapshot()) 316 if (hasSnapshot())
317 return; 317 return;
318 m_childNodes = adoptPtr(new Vector<RefPtr<Node> >()); 318 m_childNodes = adoptPtr(new Vector<RefPtr<Node> >());
319 Node* node = m_currentNode.get(); 319 Node* node = m_currentNode.get();
320 while (node) { 320 while (node) {
321 m_childNodes->append(node); 321 m_childNodes->append(node);
322 node = node->nextSibling(); 322 node = node->previousSibling();
323 } 323 }
324 } 324 }
325 325
326 ChildNodesLazySnapshot* nextSnapshot() { return m_nextSnapshot; } 326 ChildNodesLazySnapshot* nextSnapshot() { return m_nextSnapshot; }
327 bool hasSnapshot() { return !!m_childNodes.get(); } 327 bool hasSnapshot() { return !!m_childNodes.get(); }
328 328
329 static void takeChildNodesLazySnapshot() 329 static void takeChildNodesLazySnapshot()
330 { 330 {
331 ChildNodesLazySnapshot* snapshot = latestSnapshot; 331 ChildNodesLazySnapshot* snapshot = latestSnapshot;
332 while (snapshot && !snapshot->hasSnapshot()) { 332 while (snapshot && !snapshot->hasSnapshot()) {
(...skipping 25 matching lines...) Expand all
358 m_node->resumePostAttachCallbacks(); 358 m_node->resumePostAttachCallbacks();
359 } 359 }
360 360
361 private: 361 private:
362 ContainerNode* m_node; 362 ContainerNode* m_node;
363 }; 363 };
364 364
365 } // namespace WebCore 365 } // namespace WebCore
366 366
367 #endif // ContainerNode_h 367 #endif // ContainerNode_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698