Bug 66399

Summary: Reduce usages of String::createUninitialized
Product: WebKit Reporter: Annie Sullivan <sullivan>
Component: Web Template FrameworkAssignee: Annie Sullivan <sullivan>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, eric, jamesr, simonjam, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 66161    
Attachments:
Description Flags
Patch none

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.