RESOLVED FIXED 21203
Optimize appending a number to a string
https://bugs.webkit.org/show_bug.cgi?id=21203
Summary Optimize appending a number to a string
Maciej Stachowiak
Reported 2008-09-28 19:56:22 PDT
Optimize appending a number to a string. It's pretty common in real-world code (and on some of the v8 benchmarks) to do this.
Attachments
patch to do it. Some sad code duplication here. (20.34 KB, patch)
2008-09-28 19:57 PDT, Maciej Stachowiak
darin: review+
Maciej Stachowiak
Comment 1 2008-09-28 19:57:18 PDT
Created attachment 23900 [details] patch to do it. Some sad code duplication here.
Maciej Stachowiak
Comment 2 2008-09-28 20:01:01 PDT
I sadly duplicated the logic for UString::from(int) and UString::from(double) though fortunately not the actual append logic. Perhaps I should try harder to refactor to make it ot duplicat, though it was not 100% clear how to do this except maybe using a template. UString::from(int) is not much code but the double case is nontrivial.
Darin Adler
Comment 3 2008-09-28 20:12:20 PDT
Comment on attachment 23900 [details] patch to do it. Some sad code duplication here. + if ((leftIsString = v1->isString()) && v2->isString()) { Why not just put the leftIsString boolean initialization separate in front of the if statement in a more conventional way? + RefPtr<UString::Rep> value; + if (JSImmediate::isImmediate(v2)) + value = concatenate(static_cast<JSString*>(v1)->value().rep(), JSImmediate::getTruncatedInt32(v2)); + else + value = concatenate(static_cast<JSString*>(v1)->value().rep(), right); I believe would be more efficient if done with the ternary operator instead of an if statement. I believe it would save a null check and a branch over deref code on the assignment to the value local. +inline size_t expandedSize(size_t size, size_t otherSize) If this isn't going to be a static member function, then I suggest internal linkage -- add the static keyword. +inline bool expandCapacity(UString::Rep* rep, int requiredLength) This should also be marked static to get internal linkage. r=me
Maciej Stachowiak
Comment 4 2008-09-29 18:31:50 PDT
Landed as r37089
Note You need to log in before you can comment on or make changes to this bug.