WebKit Bugzilla
Attachment 372457 Details for
Bug 198997
: Add StringBuilder member function which allows makeString() style variadic argument construction
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Basic Sketch of the implementation (not tested)
basic_sketch.diff (text/plain), 2.91 KB, created by
Sam Weinig
on 2019-06-19 06:12:10 PDT
(
hide
)
Description:
Basic Sketch of the implementation (not tested)
Filename:
MIME Type:
Creator:
Sam Weinig
Created:
2019-06-19 06:12:10 PDT
Size:
2.91 KB
patch
obsolete
>Index: Source/WTF/wtf/text/StringBuilder.h >=================================================================== >--- Source/WTF/wtf/text/StringBuilder.h (revision 246586) >+++ Source/WTF/wtf/text/StringBuilder.h (working copy) >@@ -30,6 +30,7 @@ > #include <wtf/text/AtomString.h> > #include <wtf/text/IntegerToStringConversion.h> > #include <wtf/text/StringView.h> >+#include <wtf/text/StringConcatenate.h> > #include <wtf/text/WTFString.h> > > namespace WTF { >@@ -216,6 +217,9 @@ public: > template<unsigned characterCount> > ALWAYS_INLINE void appendLiteral(const char (&characters)[characterCount]) { append(characters, characterCount - 1); } > >+ template<typename... StringTypes> >+ void appendMakeString(StringTypes... strings); >+ > WTF_EXPORT_PRIVATE void appendNumber(int); > WTF_EXPORT_PRIVATE void appendNumber(unsigned); > WTF_EXPORT_PRIVATE void appendNumber(long); >@@ -359,6 +363,9 @@ private: > ALWAYS_INLINE CharType * getBufferCharacters(); > WTF_EXPORT_PRIVATE void reifyString() const; > >+ template<typename StringTypeAdapter, typename... StringTypeAdapters> >+ void appendMakeStringFromAdapters(StringTypeAdapter adapter, StringTypeAdapters ...adapters) >+ > mutable String m_string; > RefPtr<StringImpl> m_buffer; > union { >@@ -387,6 +394,49 @@ ALWAYS_INLINE UChar* StringBuilder::getB > return m_bufferCharacters16; > } > >+template<typename StringTypeAdapter, typename... StringTypeAdapters> >+void StringBuilder::appendMakeStringFromAdapters(StringTypeAdapter adapter, StringTypeAdapters ...adapters) >+{ >+ static_assert(String::MaxLength == std::numeric_limits<int32_t>::max(), ""); >+ auto sum = checkedSum<int32_t>(adapter.length(), adapters.length()...); >+ if (sum.hasOverflowed()) { >+ didOverflow(); >+ return; >+ } >+ >+ unsigned length = sum.unsafeGet(); >+ ASSERT(length <= String::MaxLength); >+ if (are8Bit(adapter, adapters...)) { >+ // FIXME: We can check overflow prior to appendUninitialized by adding current length to the checkedSum >+ // computation at function start. >+ LChar* dest = appendUninitialized<LChar>(length); >+ if (!dest) { >+ ASSERT(hasOverflowed()); >+ return; >+ } >+ >+ >+ makeStringAccumulator(dest, adapter, adapters...); >+ } else { >+ // FIXME: We can check overflow prior to appendUninitialized by adding current length to the checkedSum >+ // computation at function start. >+ UChar* dest = appendUninitialized<UChar>(length); >+ if (!dest) { >+ ASSERT(hasOverflowed()); >+ return; >+ } >+ >+ makeStringAccumulator(dest, adapter, adapters...); >+ } >+} >+ >+template<typename... StringTypes> >+void StringBuilder::appendMakeString(StringTypes... strings) >+{ >+ appendMakeStringFromAdapters(StringTypeAdapter<StringTypes>(strings)...); >+} >+ >+ > template <typename CharType> > bool equal(const StringBuilder& s, const CharType* buffer, unsigned length) > {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198997
:
372457
|
373727
|
373774
|
373782
|
374303
|
374315
|
374321