Bug 95888 - More fixes for String::operator+=() in Debug mode
Summary: More fixes for String::operator+=() in Debug mode
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Patrick R. Gansterer
URL:
Keywords:
: 95945 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-09-05 13:51 PDT by Patrick R. Gansterer
Modified: 2012-09-06 01:54 PDT (History)
5 users (show)

See Also:


Attachments
Patch (9.31 KB, patch)
2012-09-05 13:55 PDT, Patrick R. Gansterer
paroga: review-
Details | Formatted Diff | Diff
Patch (9.56 KB, patch)
2012-09-05 14:08 PDT, Patrick R. Gansterer
abarth: review+
Details | Formatted Diff | Diff
Patch (10.67 KB, patch)
2012-09-05 14:17 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick R. Gansterer 2012-09-05 13:51:35 PDT
More fixes for String::operator+=() in Debug mode
Comment 1 Patrick R. Gansterer 2012-09-05 13:55:37 PDT
Created attachment 162325 [details]
Patch
Comment 2 Patrick R. Gansterer 2012-09-05 14:03:07 PDT
Comment on attachment 162325 [details]
Patch

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

> Source/WebCore/editing/VisibleSelection.cpp:678
>          result = "<none>";

won't work
Comment 3 Adam Barth 2012-09-05 14:03:50 PDT
Comment on attachment 162325 [details]
Patch

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

> Source/WebCore/dom/Element.cpp:1421
> +    strncpy(buffer, result.toString().utf8().data(), length - 1);

We should explicitly NUL terminate buffer in case we hit the length limit, but that's something for another patch.

> Source/WebCore/dom/Node.cpp:2105
> +        if (!attr.isEmpty())
> +            string.append(attrDesc + attr);

It's more efficient to do this in two operations.  Having the + as a separate operation creates an intermediate buffer that's not needed.

> Source/WebCore/dom/Node.cpp:2198
> -                traverseTreeAndMark(indent + "\t", youngerShadowRoot, markedNode1, markedLabel1, markedNode2, markedLabel2);
> +                traverseTreeAndMark(indent.toString() + '\t', youngerShadowRoot, markedNode1, markedLabel1, markedNode2, markedLabel2);

It's more efficient to append the '\t' and then call toString.

> Source/WebCore/dom/Node.cpp:2200
> -            traverseTreeAndMark(indent + "\t", oldestShadowRoot, markedNode1, markedLabel1, markedNode2, markedLabel2);
> +            traverseTreeAndMark(indent.toString() + '\t', oldestShadowRoot, markedNode1, markedLabel1, markedNode2, markedLabel2);

ditto

> Source/WebCore/dom/Node.cpp:2222
> +    if (s.length())

if (!s.isEmpty())
Comment 4 Patrick R. Gansterer 2012-09-05 14:08:49 PDT
Created attachment 162329 [details]
Patch
Comment 5 Patrick R. Gansterer 2012-09-05 14:10:32 PDT
Comment on attachment 162329 [details]
Patch

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

> Source/WebCore/dom/Node.cpp:2105
> +            string.append(attrDesc + attr);

string is an out-parameter
are two String::append() calls better than one append and operator+()?
Comment 6 Adam Barth 2012-09-05 14:12:54 PDT
Comment on attachment 162329 [details]
Patch

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

>> Source/WebCore/dom/Node.cpp:2105
>> +            string.append(attrDesc + attr);
> 
> string is an out-parameter
> are two String::append() calls better than one append and operator+()?

Can we change the outparameter type to StringBuilder?
Comment 7 Patrick R. Gansterer 2012-09-05 14:17:49 PDT
Created attachment 162333 [details]
Patch
Comment 8 Adam Barth 2012-09-06 00:46:34 PDT
Comment on attachment 162333 [details]
Patch

Clearing flags on attachment: 162333

Committed r127706: <http://trac.webkit.org/changeset/127706>
Comment 9 Adam Barth 2012-09-06 00:46:36 PDT
All reviewed patches have been landed.  Closing bug.
Comment 10 Chris Dumez 2012-09-06 01:54:08 PDT
*** Bug 95945 has been marked as a duplicate of this bug. ***