Commit f5683607 authored by jbroman's avatar jbroman Committed by Commit bot

wtf: Implement StringView specialization of string concatenation.

Convert String and AtomicString specializations, which are trivially converted
to StringView, to inherit from it as well.

Add one site which uses the StringView specialization.

Review-Url: https://codereview.chromium.org/2359663002
Cr-Commit-Position: refs/heads/master@{#420680}
parent dbb85e45
......@@ -239,7 +239,7 @@ v8::Maybe<bool> V8ScriptValueSerializer::WriteHostObject(v8::Isolate* isolate, v
return v8::Just(true);
}
if (!exceptionState.hadException()) {
String interface = wrappable->wrapperTypeInfo()->interfaceName;
StringView interface = wrappable->wrapperTypeInfo()->interfaceName;
exceptionState.throwDOMException(DataCloneError, interface + " object could not be cloned.");
}
return v8::Nothing<bool>();
......
......@@ -118,32 +118,18 @@ void WTF::StringTypeAdapter<Vector<LChar>>::writeTo(UChar* destination)
destination[i] = m_buffer[i];
}
void WTF::StringTypeAdapter<String>::writeTo(LChar* destination)
void WTF::StringTypeAdapter<StringView>::writeTo(LChar* destination)
{
unsigned length = m_buffer.length();
ASSERT(is8Bit());
const LChar* data = m_buffer.characters8();
for (unsigned i = 0; i < length; ++i)
destination[i] = data[i];
DCHECK(is8Bit());
StringImpl::copyChars(destination, m_view.characters8(), m_view.length());
WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
}
void WTF::StringTypeAdapter<String>::writeTo(UChar* destination)
void WTF::StringTypeAdapter<StringView>::writeTo(UChar* destination)
{
unsigned length = m_buffer.length();
if (is8Bit()) {
const LChar* data = m_buffer.characters8();
for (unsigned i = 0; i < length; ++i)
destination[i] = data[i];
} else {
const UChar* data = m_buffer.characters16();
for (unsigned i = 0; i < length; ++i)
destination[i] = data[i];
}
if (is8Bit())
StringImpl::copyChars(destination, m_view.characters8(), m_view.length());
else
StringImpl::copyChars(destination, m_view.characters16(), m_view.length());
WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
}
......@@ -264,44 +264,33 @@ private:
};
template<>
class WTF_EXPORT StringTypeAdapter<String> {
class WTF_EXPORT StringTypeAdapter<StringView> {
DISALLOW_NEW();
public:
StringTypeAdapter<String>(const String& string)
: m_buffer(string)
{
}
unsigned length() { return m_buffer.length(); }
bool is8Bit() { return m_buffer.isNull() || m_buffer.is8Bit(); }
StringTypeAdapter(const StringView& view)
: m_view(view) {}
unsigned length() { return m_view.length(); }
bool is8Bit() { return m_view.is8Bit(); }
void writeTo(LChar* destination);
void writeTo(UChar* destination);
private:
const String& m_buffer;
const StringView m_view;
};
template<>
class StringTypeAdapter<AtomicString> {
DISALLOW_NEW();
class StringTypeAdapter<String> : public StringTypeAdapter<StringView> {
public:
StringTypeAdapter<AtomicString>(const AtomicString& string)
: m_adapter(string.getString())
{
}
unsigned length() { return m_adapter.length(); }
bool is8Bit() { return m_adapter.is8Bit(); }
void writeTo(LChar* destination) { m_adapter.writeTo(destination); }
void writeTo(UChar* destination) { m_adapter.writeTo(destination); }
StringTypeAdapter(const String& string)
: StringTypeAdapter<StringView>(string) {}
};
private:
StringTypeAdapter<String> m_adapter;
template<>
class StringTypeAdapter<AtomicString> : public StringTypeAdapter<StringView> {
public:
StringTypeAdapter(const AtomicString& string)
: StringTypeAdapter<StringView>(string) {}
};
inline void sumWithOverflow(unsigned& total, unsigned addend, bool& overflow)
......
......@@ -134,6 +134,11 @@ inline StringAppend<const char*, AtomicString> operator+(const char* string1, co
return StringAppend<const char*, AtomicString>(string1, string2);
}
inline StringAppend<const char*, StringView> operator+(const char* string1, const StringView& string2)
{
return StringAppend<const char*, StringView>(string1, string2);
}
template<typename U, typename V>
inline StringAppend<const char*, StringAppend<U, V>> operator+(const char* string1, const StringAppend<U, V>& string2)
{
......@@ -150,6 +155,11 @@ inline StringAppend<const UChar*, AtomicString> operator+(const UChar* string1,
return StringAppend<const UChar*, AtomicString>(string1, string2);
}
inline StringAppend<const UChar*, StringView> operator+(const UChar* string1, const StringView& string2)
{
return StringAppend<const UChar*, StringView>(string1, string2);
}
template<typename U, typename V>
inline StringAppend<const UChar*, StringAppend<U, V>> operator+(const UChar* string1, const StringAppend<U, V>& string2)
{
......@@ -162,6 +172,18 @@ StringAppend<String, T> operator+(const String& string1, T string2)
return StringAppend<String, T>(string1, string2);
}
template<typename T>
StringAppend<AtomicString, T> operator+(const AtomicString& string1, T string2)
{
return StringAppend<AtomicString, T>(string1, string2);
}
template<typename T>
StringAppend<StringView, T> operator+(const StringView& string1, T string2)
{
return StringAppend<StringView, T>(string1, string2);
}
template<typename U, typename V, typename W>
StringAppend<StringAppend<U, V>, W> operator+(const StringAppend<U, V>& string1, W string2)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment