Bug 66399 - Reduce usages of String::createUninitialized
Summary: Reduce usages of String::createUninitialized
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Annie Sullivan
URL:
Keywords:
Depends on:
Blocks: 66161
  Show dependency treegraph
 
Reported: 2011-08-17 13:04 PDT by Annie Sullivan
Modified: 2011-08-17 21:23 PDT (History)
5 users (show)

See Also:


Attachments
Patch (7.30 KB, patch)
2011-08-17 13:08 PDT, Annie Sullivan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Annie Sullivan 2011-08-17 13:04:04 PDT
WTF::String is supposed to be immutable, but createUninitialized() allows callers to hang on to a non-const reference to the underlying data buffer. Some of these usages could be replaced by StringBuilder.
Comment 1 Annie Sullivan 2011-08-17 13:08:52 PDT
Created attachment 104219 [details]
Patch
Comment 2 Annie Sullivan 2011-08-17 13:09:25 PDT
If anyone has suggestions for performance benchmark tests to run before submitting, please comment.
Comment 3 James Robinson 2011-08-17 13:12:04 PDT
PerformanceTests/Parser has a good test for the html parser.  I'm not sure if that test hits these codepaths or not.
Comment 4 Annie Sullivan 2011-08-17 13:40:49 PDT
(In reply to comment #3)
> PerformanceTests/Parser has a good test for the html parser.  I'm not sure if that test hits these codepaths or not.

Numbers from html-parser.html look similar before/after applying my patch.

Before patch:
avg 1605.3
median 1604
stdev 9.935290634903437
min 1594
max 1629

After patch:
avg 1595.1
median 1592
stdev 6.579513659838393
min 1589
max 1609
Comment 5 Adam Barth 2011-08-17 14:04:44 PDT
Comment on attachment 104219 [details]
Patch

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

> Source/WebCore/html/parser/HTMLSourceTracker.cpp:59
> +    int length = token.endIndex() - token.startIndex();

int => size_t probably
Comment 6 Adam Barth 2011-08-17 14:06:55 PDT
There shouldn't be any perf impact.  ReserveCapacity effectively does the same thing by pre-allocating the buffer.
Comment 7 WebKit Review Bot 2011-08-17 21:23:13 PDT
Comment on attachment 104219 [details]
Patch

Clearing flags on attachment: 104219

Committed r93281: <http://trac.webkit.org/changeset/93281>
Comment 8 WebKit Review Bot 2011-08-17 21:23:18 PDT
All reviewed patches have been landed.  Closing bug.