Bug 127266 - Add a nicer way to iterate over all the attributes of an element
Summary: Add a nicer way to iterate over all the attributes of an element
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Benjamin Poulain
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-19 23:24 PST by Benjamin Poulain
Modified: 2014-01-20 17:27 PST (History)
0 users

See Also:


Attachments
Patch (29.78 KB, patch)
2014-01-19 23:33 PST, Benjamin Poulain
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Poulain 2014-01-19 23:24:09 PST
Add a nicer way to iterate over all the attributes of an element
Comment 1 Benjamin Poulain 2014-01-19 23:33:29 PST
Created attachment 221620 [details]
Patch
Comment 2 Anders Carlsson 2014-01-20 09:13:41 PST
Comment on attachment 221620 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=221620&action=review

> Source/WebCore/dom/ElementData.h:73
> +class AttributeIteratorAccessor {
> +public:
> +    AttributeIteratorAccessor(const Attribute* array, unsigned size)
> +        : m_array(array)
> +        , m_size(size)
> +    {
> +    }
> +
> +    AttributeConstIterator begin() const { return AttributeConstIterator(m_array, 0); }
> +    AttributeConstIterator end() const { return AttributeConstIterator(m_array, m_size); }
> +private:
> +    const Attribute* m_array;
> +    unsigned m_size;
> +};

I think you can use WTF::IteratorRange here instead.
Comment 3 Geoffrey Garen 2014-01-20 09:30:44 PST
Comment on attachment 221620 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=221620&action=review

r=me

Please consider Anders's suggestion.

> Source/WebCore/dom/ElementData.cpp:182
> +    unsigned count = length();

In cases like this, I prefer "unsigned length = this->length()" or "unsigned length = ElementData::length()". It's bad when one thing becomes two. Taking "length" and renaming it to "count" makes it seem like you've changed it somehow, which can be confusing.
Comment 4 Benjamin Poulain 2014-01-20 17:07:09 PST
(In reply to comment #2)
> I think you can use WTF::IteratorRange here instead.

My first idea was to just use the Attribute* as the iterator. But for some reason clang really sucks iterating with pointers :(
Comment 5 Benjamin Poulain 2014-01-20 17:27:38 PST
Committed r162394: <http://trac.webkit.org/changeset/162394>