Don't bother special-casing one-byte strings as they're more complicated than it seemed

This commit is contained in:
Thomas Goyne 2018-06-21 11:34:37 -07:00
parent 1838f1f932
commit 3c45c8a750

View File

@ -48,16 +48,9 @@ inline String<node::Types>::String(const v8::Local<v8::String> &s) {
if (s.IsEmpty() || s->Length() == 0) {
return;
}
if (s->IsOneByte()) {
m_str.resize(s->Length());
}
else {
// Length is in UCS-2 code units, which can take up to 3 bytes each to encode
m_str.resize(3 * s->Length());
}
m_str.resize(s->Utf8Length());
const int flags = v8::String::NO_NULL_TERMINATION | v8::String::REPLACE_INVALID_UTF8;
auto length = s->WriteUtf8(&m_str[0], m_str.size(), 0, flags);
m_str.resize(length);
s->WriteUtf8(&m_str[0], m_str.size(), 0, flags);
}
} // js