Bug 77574 - Avoid creating NamedNodeMap unnecessarily
Summary: Avoid creating NamedNodeMap unnecessarily
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: Caio Marcelo de Oliveira Filho
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-01 13:26 PST by Caio Marcelo de Oliveira Filho
Modified: 2012-02-01 16:20 PST (History)
6 users (show)

See Also:


Attachments
Patch (44.35 KB, patch)
2012-02-01 13:34 PST, Caio Marcelo de Oliveira Filho
no flags Details | Formatted Diff | Diff
Patch (44.23 KB, patch)
2012-02-01 15:21 PST, Caio Marcelo de Oliveira Filho
no flags Details | Formatted Diff | Diff
Patch (45.71 KB, patch)
2012-02-01 15:28 PST, Caio Marcelo de Oliveira Filho
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Caio Marcelo de Oliveira Filho 2012-02-01 13:26:08 PST
Avoid creating NamedNodeMap unnecessarily
Comment 1 Caio Marcelo de Oliveira Filho 2012-02-01 13:31:27 PST
This is related to work I'm doing for bug 75069.
Comment 2 Caio Marcelo de Oliveira Filho 2012-02-01 13:34:23 PST
Created attachment 125007 [details]
Patch
Comment 3 Ryosuke Niwa 2012-02-01 13:57:22 PST
Comment on attachment 125007 [details]
Patch

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

> Source/WebCore/dom/Element.h:220
> +    NamedNodeMap* ensureAttributes() const;

I'd call this one ensureUpdatedAttributes() to be consistent.

> Source/WebCore/dom/Node.cpp:1836
> -                NamedNodeMap* attrs = elem->attributes();
> -                
> +                NamedNodeMap* attrs = elem->attributeMap();
> +

It seems dangerous to rely on the fact hasAttributes have updated the attributes. Given that updateInvalidAttributes should be fast when there are no updates required, I'd prefer leaving as is (or replace it with updatedAttributes).

> Source/WebCore/dom/Node.cpp:1923
> -                NamedNodeMap *attrs = elem->attributes();
> +                NamedNodeMap* attrs = elem->attributeMap();

Ditto.

> Source/WebCore/dom/Node.cpp:1979
> +        if (NamedNodeMap* attrs = toElement(this)->attributeMap()) {

Ditto.

> Source/WebCore/editing/CompositeEditCommand.cpp:316
> +    if (!node->isElementNode())
> +        return true;
> +
> +    const NamedNodeMap* attributeMap = toElement(node)->updatedAttributes();
>      if (!attributeMap || attributeMap->isEmpty())
>          return true;

We can just call hasAttributes here.

> Source/WebCore/editing/htmlediting.cpp:1168
> +    // Neither element have attributes, so they are the same.

I don't think we need this comment.

> Source/WebCore/xml/XPathFunctions.cpp:595
> +        if (node->isElementNode() && toElement(node)->hasAttributes())
> +            languageAttribute = toElement(node)->attributeMap()->getAttributeItem(XMLNames::langAttr);

You're adding unnecessary updates of style and SVG animation attributes implicitly in hasAttributes. I don't think we should do this.
Comment 4 Ryosuke Niwa 2012-02-01 13:59:21 PST
In general, this refactoring looks great. It clarifies semantics in many call sites of attributes.
Comment 5 WebKit Review Bot 2012-02-01 14:41:25 PST
Comment on attachment 125007 [details]
Patch

Attachment 125007 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/11396581
Comment 6 Caio Marcelo de Oliveira Filho 2012-02-01 15:20:50 PST
Comment on attachment 125007 [details]
Patch

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

>> Source/WebCore/dom/Element.h:220
>> +    NamedNodeMap* ensureAttributes() const;
> 
> I'd call this one ensureUpdatedAttributes() to be consistent.

Fixed.

>> Source/WebCore/dom/Node.cpp:1836
>> +
> 
> It seems dangerous to rely on the fact hasAttributes have updated the attributes. Given that updateInvalidAttributes should be fast when there are no updates required, I'd prefer leaving as is (or replace it with updatedAttributes).

I agree. I changed this pattern to "if (NamedNodeMap* attrs = elem->updatedAttributes())". If is empty we will enter the conditional but not run any iteration in the loop inside.

>> Source/WebCore/editing/CompositeEditCommand.cpp:316
>>          return true;
> 
> We can just call hasAttributes here.

Of course! :-) Fixed.

>> Source/WebCore/editing/htmlediting.cpp:1168
>> +    // Neither element have attributes, so they are the same.
> 
> I don't think we need this comment.

Fixed.

>> Source/WebCore/xml/XPathFunctions.cpp:595
>> +            languageAttribute = toElement(node)->attributeMap()->getAttributeItem(XMLNames::langAttr);
> 
> You're adding unnecessary updates of style and SVG animation attributes implicitly in hasAttributes. I don't think we should do this.

No. Previous call to node->attributes() (now known as ensureUpdatedAttributes()) would update style and SVG animation attributes.

I also rewrote the code to avoid using hasAttribute()/attributeMap().
Comment 7 Caio Marcelo de Oliveira Filho 2012-02-01 15:21:12 PST
Created attachment 125030 [details]
Patch
Comment 8 Ryosuke Niwa 2012-02-01 15:23:34 PST
(In reply to comment #5)
> (From update of attachment 125007 [details])
> Attachment 125007 [details] did not pass chromium-ews (chromium-xvfb):
> Output: http://queues.webkit.org/results/11396581

It appears that you have to modify Source/WebKit/chromium/src/WebPageSerializerImpl.cpp
Comment 9 Caio Marcelo de Oliveira Filho 2012-02-01 15:28:20 PST
Created attachment 125033 [details]
Patch
Comment 10 WebKit Review Bot 2012-02-01 16:20:54 PST
Comment on attachment 125033 [details]
Patch

Clearing flags on attachment: 125033

Committed r106515: <http://trac.webkit.org/changeset/106515>
Comment 11 WebKit Review Bot 2012-02-01 16:20:59 PST
All reviewed patches have been landed.  Closing bug.