OLD | NEW |
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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 ~ChildNodesLazySnapshot() | 338 ~ChildNodesLazySnapshot() |
339 { | 339 { |
340 latestSnapshot = m_nextSnapshot; | 340 latestSnapshot = m_nextSnapshot; |
341 } | 341 } |
342 | 342 |
343 // Returns 0 if there is no next Node. | 343 // Returns 0 if there is no next Node. |
344 Node* nextNode() | 344 Node* nextNode() |
345 { | 345 { |
346 if (LIKELY(!hasSnapshot())) { | 346 if (LIKELY(!hasSnapshot())) { |
347 Node* node = m_currentNode; | 347 Node* node = m_currentNode.get(); |
348 if (m_currentNode) | 348 if (m_currentNode) |
349 m_currentNode = m_currentNode->nextSibling(); | 349 m_currentNode = m_currentNode->nextSibling(); |
350 return node; | 350 return node; |
351 } | 351 } |
352 Vector<RefPtr<Node> >* nodeVector = m_childNodes.get(); | 352 Vector<RefPtr<Node> >* nodeVector = m_childNodes.get(); |
353 if (m_currentIndex >= nodeVector->size()) | 353 if (m_currentIndex >= nodeVector->size()) |
354 return 0; | 354 return 0; |
355 return (*nodeVector)[m_currentIndex++].get(); | 355 return (*nodeVector)[m_currentIndex++].get(); |
356 } | 356 } |
357 | 357 |
358 void takeSnapshot() | 358 void takeSnapshot() |
359 { | 359 { |
360 if (hasSnapshot()) | 360 if (hasSnapshot()) |
361 return; | 361 return; |
362 m_childNodes = adoptPtr(new Vector<RefPtr<Node> >()); | 362 m_childNodes = adoptPtr(new Vector<RefPtr<Node> >()); |
363 Node* node = m_currentNode; | 363 Node* node = m_currentNode.get(); |
364 while (node) { | 364 while (node) { |
365 m_childNodes->append(node); | 365 m_childNodes->append(node); |
366 node = node->nextSibling(); | 366 node = node->nextSibling(); |
367 } | 367 } |
368 } | 368 } |
369 | 369 |
370 ChildNodesLazySnapshot* nextSnapshot() { return m_nextSnapshot; } | 370 ChildNodesLazySnapshot* nextSnapshot() { return m_nextSnapshot; } |
371 bool hasSnapshot() { return !!m_childNodes.get(); } | 371 bool hasSnapshot() { return !!m_childNodes.get(); } |
372 | 372 |
373 static void takeChildNodesLazySnapshot() | 373 static void takeChildNodesLazySnapshot() |
374 { | 374 { |
375 ChildNodesLazySnapshot* snapshot = latestSnapshot; | 375 ChildNodesLazySnapshot* snapshot = latestSnapshot; |
376 while (snapshot && !snapshot->hasSnapshot()) { | 376 while (snapshot && !snapshot->hasSnapshot()) { |
377 snapshot->takeSnapshot(); | 377 snapshot->takeSnapshot(); |
378 snapshot = snapshot->nextSnapshot(); | 378 snapshot = snapshot->nextSnapshot(); |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 private: | 382 private: |
383 static ChildNodesLazySnapshot* latestSnapshot; | 383 static ChildNodesLazySnapshot* latestSnapshot; |
384 | 384 |
385 Node* m_currentNode; | 385 RefPtr<Node> m_currentNode; |
386 unsigned m_currentIndex; | 386 unsigned m_currentIndex; |
387 OwnPtr<Vector<RefPtr<Node> > > m_childNodes; // Lazily instantiated. | 387 OwnPtr<Vector<RefPtr<Node> > > m_childNodes; // Lazily instantiated. |
388 ChildNodesLazySnapshot* m_nextSnapshot; | 388 ChildNodesLazySnapshot* m_nextSnapshot; |
389 }; | 389 }; |
390 | 390 |
391 } // namespace WebCore | 391 } // namespace WebCore |
392 | 392 |
393 #endif // ContainerNode_h | 393 #endif // ContainerNode_h |
OLD | NEW |