Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Issue 2315853002: Massively simplify WTF's StringConcatenate (Closed)

Created:
4 years, 3 months ago by esprehn
Modified:
3 years, 7 months ago
CC:
blink-reviews, blink-reviews-wtf_chromium.org, chromium-reviews, Mikhail
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Massively simplify WTF's StringConcatenate This does a number of simplifications to remove most of the StringConcatenate code: - Delegate const char* to const LChar* so we don't have code duplication. - Use StringImpl::copyChars instead of manual loops. This is less code and will also use memcpy when possible so it's much faster. - Remove the Vector versions of StringTypeAdapter, they aren't used, and doing string + vector is very weird, I don't think we need to support this. - Add missing const to everything, but also store the String values and adapters by value instead of refs. This avoids any issues with temporary strings. - Merge StringOperators into StringConcatenate. - Use CheckedNumeric instead of the manual sumWithOverflow. This code was bad since it made string1 + string2 return a nullptr when there was overflow which was likely to crash since code assumes that string concat will never result in null. We now crash gracefully inside ValueOrDie() instead when this happens. - Make all related classes STACK_ALLOCATED() instead of DISALLOW_NEW(), the classes should never be members in heap objects. - Keep the StringTypeAdapters as a member in StringAppend, then keep the adapters as members. Then I merged makeString into StringAppend reusing the is8Bit and writeTo logic removing lots of code. NOTE: This patch removes the ability to do string + non-const-UChar* or non-const-LChar*. In practice this is never done, and the simplification seems worth it.

Patch Set 1 #

Patch Set 2 : no really. #

Patch Set 3 : missing inlines. #

Total comments: 4
Unified diffs Side-by-side diffs Delta from patch set Stats (+174 lines, -696 lines) Patch
M third_party/WebKit/Source/core/frame/csp/CSPDirectiveListTest.cpp View 1 1 chunk +0 lines, -1 line 0 comments Download
M third_party/WebKit/Source/wtf/BUILD.gn View 1 2 chunks +1 line, -2 lines 0 comments Download
M third_party/WebKit/Source/wtf/text/StringConcatenate.h View 1 2 1 chunk +142 lines, -222 lines 4 comments Download
M third_party/WebKit/Source/wtf/text/StringConcatenate.cpp View 1 1 chunk +27 lines, -109 lines 0 comments Download
A + third_party/WebKit/Source/wtf/text/StringConcatenateTest.cpp View 1 1 chunk +4 lines, -3 lines 0 comments Download
D third_party/WebKit/Source/wtf/text/StringOperators.h View 1 1 chunk +0 lines, -173 lines 0 comments Download
D third_party/WebKit/Source/wtf/text/StringOperatorsTest.cpp View 1 1 chunk +0 lines, -186 lines 0 comments Download

Messages

Total messages: 24 (16 generated)
esprehn
4 years, 3 months ago (2016-09-07 08:38:52 UTC) #14
Yuta Kitamura
Looks mostly okay. https://codereview.chromium.org/2315853002/diff/40001/third_party/WebKit/Source/wtf/text/StringConcatenate.h File third_party/WebKit/Source/wtf/text/StringConcatenate.h (right): https://codereview.chromium.org/2315853002/diff/40001/third_party/WebKit/Source/wtf/text/StringConcatenate.h#newcode145 third_party/WebKit/Source/wtf/text/StringConcatenate.h:145: const String m_buffer; I don't think ...
4 years, 3 months ago (2016-09-07 10:25:39 UTC) #18
esprehn
https://codereview.chromium.org/2315853002/diff/40001/third_party/WebKit/Source/wtf/text/StringConcatenate.h File third_party/WebKit/Source/wtf/text/StringConcatenate.h (right): https://codereview.chromium.org/2315853002/diff/40001/third_party/WebKit/Source/wtf/text/StringConcatenate.h#newcode145 third_party/WebKit/Source/wtf/text/StringConcatenate.h:145: const String m_buffer; On 2016/09/07 at 10:25:39, Yuta Kitamura ...
4 years, 3 months ago (2016-09-07 16:21:26 UTC) #19
Jeffrey Yasskin
https://codereview.chromium.org/2315853002/diff/40001/third_party/WebKit/Source/wtf/text/StringConcatenate.h File third_party/WebKit/Source/wtf/text/StringConcatenate.h (right): https://codereview.chromium.org/2315853002/diff/40001/third_party/WebKit/Source/wtf/text/StringConcatenate.h#newcode145 third_party/WebKit/Source/wtf/text/StringConcatenate.h:145: const String m_buffer; On 2016/09/07 16:21:26, esprehn wrote: > ...
4 years, 3 months ago (2016-09-07 18:53:01 UTC) #20
esprehn
I talked to jeffery offline about this, and he thinks this is probably an improvement ...
4 years, 3 months ago (2016-09-08 01:19:34 UTC) #21
haraken
LGTM on my side.
4 years, 3 months ago (2016-09-08 01:36:42 UTC) #22
Yuta Kitamura
LGTM in landing this, but I still wonder why const ref used to work and ...
4 years, 3 months ago (2016-09-08 05:09:31 UTC) #23
esprehn
4 years, 3 months ago (2016-09-08 22:01:07 UTC) #24
On 2016/09/08 at 05:09:31, yutak wrote:
> LGTM in landing this, but I still wonder why const ref used
> to work and it doesn't with this change. It may be good
> to split this patch into smaller ones so the issue can be
> spotted more easily.

Yeah that's totally fair, I'll split it up. :)

> 
>
https://codereview.chromium.org/2315853002/diff/40001/third_party/WebKit/Sour...
> File third_party/WebKit/Source/wtf/text/StringConcatenate.h (right):
> 
>
https://codereview.chromium.org/2315853002/diff/40001/third_party/WebKit/Sour...
> third_party/WebKit/Source/wtf/text/StringConcatenate.h:145: const String
m_buffer;
> Ah sorry, I wasn't aware the tests were disabled already.

Powered by Google App Engine
This is Rietveld 408576698