Title: [184309] trunk/Source/WebCore
- Revision
- 184309
- Author
- [email protected]
- Date
- 2015-05-13 15:06:45 -0700 (Wed, 13 May 2015)
Log Message
Modernize ContainerNode::childElementCount
https://bugs.webkit.org/show_bug.cgi?id=144930
Patch by Sam Weinig <[email protected]> on 2015-05-13
Reviewed by Darin Adler.
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::childElementCount):
Use std::distance to compute the number of child elements.
* dom/ElementChildIterator.h:
Add typedefs to make the child element iterators conform STL standards.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (184308 => 184309)
--- trunk/Source/WebCore/ChangeLog 2015-05-13 21:58:41 UTC (rev 184308)
+++ trunk/Source/WebCore/ChangeLog 2015-05-13 22:06:45 UTC (rev 184309)
@@ -1,3 +1,17 @@
+2015-05-13 Sam Weinig <[email protected]>
+
+ Modernize ContainerNode::childElementCount
+ https://bugs.webkit.org/show_bug.cgi?id=144930
+
+ Reviewed by Darin Adler.
+
+ * dom/ContainerNode.cpp:
+ (WebCore::ContainerNode::childElementCount):
+ Use std::distance to compute the number of child elements.
+
+ * dom/ElementChildIterator.h:
+ Add typedefs to make the child element iterators conform STL standards.
+
2015-05-13 Ryosuke Niwa <[email protected]>
REGRESSION(r183770): Crash inside WebEditorClient::shouldApplyStyle when applying underline
Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (184308 => 184309)
--- trunk/Source/WebCore/dom/ContainerNode.cpp 2015-05-13 21:58:41 UTC (rev 184308)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp 2015-05-13 22:06:45 UTC (rev 184309)
@@ -52,6 +52,7 @@
#include "SVGNames.h"
#include "SelectorQuery.h"
#include "TemplateContentDocumentFragment.h"
+#include <algorithm>
#include <wtf/CurrentTime.h>
namespace WebCore {
@@ -929,13 +930,8 @@
{
ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
- unsigned count = 0;
- Node* n = firstChild();
- while (n) {
- count += n->isElementNode();
- n = n->nextSibling();
- }
- return count;
+ auto children = childrenOfType<Element>(*this);
+ return std::distance(children.begin(), children.end());
}
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/ElementChildIterator.h (184308 => 184309)
--- trunk/Source/WebCore/dom/ElementChildIterator.h 2015-05-13 21:58:41 UTC (rev 184308)
+++ trunk/Source/WebCore/dom/ElementChildIterator.h 2015-05-13 22:06:45 UTC (rev 184309)
@@ -33,6 +33,12 @@
template <typename ElementType>
class ElementChildIterator : public ElementIterator<ElementType> {
public:
+ typedef ElementType value_type;
+ typedef ptrdiff_t difference_type;
+ typedef ElementType* pointer;
+ typedef ElementType& reference;
+ typedef std::forward_iterator_tag iterator_category;
+
ElementChildIterator(const ContainerNode& parent);
ElementChildIterator(const ContainerNode& parent, ElementType* current);
ElementChildIterator& operator++();
@@ -41,6 +47,12 @@
template <typename ElementType>
class ElementChildConstIterator : public ElementConstIterator<ElementType> {
public:
+ typedef const ElementType value_type;
+ typedef ptrdiff_t difference_type;
+ typedef const ElementType* pointer;
+ typedef const ElementType& reference;
+ typedef std::forward_iterator_tag iterator_category;
+
ElementChildConstIterator(const ContainerNode& parent);
ElementChildConstIterator(const ContainerNode& parent, const ElementType* current);
ElementChildConstIterator& operator++();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes