Bug 82028 - cssText should use StringBuilder
Summary: cssText should use StringBuilder
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords:
Depends on:
Blocks: 81737
  Show dependency treegraph
 
Reported: 2012-03-23 00:07 PDT by Ryosuke Niwa
Modified: 2012-03-23 04:37 PDT (History)
8 users (show)

See Also:


Attachments
Cleanup (5.17 KB, patch)
2012-03-23 02:06 PDT, Ryosuke Niwa
morrita: review+
rniwa: commit-queue+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2012-03-23 00:07:09 PDT
StylePropertySet::asText should use StringBuilder instead of adding bunch of string literals and String by operator+ and operator+=.
Comment 1 Ryosuke Niwa 2012-03-23 02:06:51 PDT
Created attachment 133446 [details]
Cleanup
Comment 2 Ryosuke Niwa 2012-03-23 02:52:36 PDT
Committed r111845: <http://trac.webkit.org/changeset/111845>
Comment 3 Nikolas Zimmermann 2012-03-23 04:08:55 PDT
Just came across your commit message:
"Make StylePropertySet::asText more efficient by deploying StringBuilder; avoids heap churn by String::operator+ and String::operator+=."

First of all this change is great and correct. For cases like this StringBuilder should be used (if we don't know before of many parts it consists, aka. how big the final string is).

But "String a = stringB + "C" + "D" + stringC" doesn't involve any heap churns anymore, only String::operator+= is inefficient, String::operator+ uses magic, to avoid any immediate heap allocations, by figuring out the final buffer size before.

So whenever you want to concat three strings (not necessarily of the same types, eg. a const char* with a String and an AtomicString), using String::operator+ is the easiest and most performant way.
(Have a look at the StringAppend<> template stuff).

Just wanted to let you know :-)
Comment 4 Ryosuke Niwa 2012-03-23 04:29:43 PDT
(In reply to comment #3)
> Just came across your commit message:
> "Make StylePropertySet::asText more efficient by deploying StringBuilder; avoids heap churn by String::operator+ and String::operator+=."
> 
> First of all this change is great and correct. For cases like this StringBuilder should be used (if we don't know before of many parts it consists, aka. how big the final string is).
> 
> But "String a = stringB + "C" + "D" + stringC" doesn't involve any heap churns anymore, only String::operator+= is inefficient, String::operator+ uses magic, to avoid any immediate heap allocations, by figuring out the final buffer size before.

Okay, I wasn't sure if that optimization had been landed or not. Good to know it's in there :) Is it defined in WTFString.h?
Comment 5 Nikolas Zimmermann 2012-03-23 04:37:33 PDT
(In reply to comment #4)
> Okay, I wasn't sure if that optimization had been landed or not. Good to know it's in there :) Is it defined in WTFString.h?
wtf/text/text/StringOperators.h and StringConcatenate.h contain the code.