X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/93a3786624b2768d89bfa27e46598dc64e2fb70a..cb9aa2694aba0ae4f946ed34b8e0f6c99c1cfe44:/runtime/JSStringBuilder.h diff --git a/runtime/JSStringBuilder.h b/runtime/JSStringBuilder.h index 5d4960e..63e51a3 100644 --- a/runtime/JSStringBuilder.h +++ b/runtime/JSStringBuilder.h @@ -32,6 +32,7 @@ namespace JSC { +// FIXME: Should move the last few callers over from this to WTF::StringBuilder. class JSStringBuilder { public: JSStringBuilder() @@ -40,72 +41,63 @@ public: { } - void append(const UChar u) + void append(LChar character) { if (m_is8Bit) { - if (u < 0xff) { - LChar c = u; - m_okay &= buffer8.tryAppend(&c, 1); + m_okay &= buffer8.tryAppend(&character, 1); + return; + } + UChar upconvertedCharacter = character; + m_okay &= buffer16.tryAppend(&upconvertedCharacter, 1); + } + + void append(UChar character) + { + if (m_is8Bit) { + if (character < 0x100) { + LChar narrowedCharacter = character; + m_okay &= buffer8.tryAppend(&narrowedCharacter, 1); return; } upConvert(); } - m_okay &= buffer16.tryAppend(&u, 1); + m_okay &= buffer16.tryAppend(&character, 1); } void append(const char* str) { - append(str, strlen(str)); + append(reinterpret_cast(str), strlen(str)); } - void append(const char* str, size_t len) + JSValue build(ExecState* exec) { + if (!m_okay) + return throwOutOfMemoryError(exec); if (m_is8Bit) { - m_okay &= buffer8.tryAppend(reinterpret_cast(str), len); - return; - } - m_okay &= buffer8.tryReserveCapacity(buffer16.size() + len); - for (size_t i = 0; i < len; i++) { - UChar u = static_cast(str[i]); - m_okay &= buffer16.tryAppend(&u, 1); + buffer8.shrinkToFit(); + if (!buffer8.data()) + return throwOutOfMemoryError(exec); + return jsString(exec, String::adopt(buffer8)); } + buffer16.shrinkToFit(); + if (!buffer16.data()) + return throwOutOfMemoryError(exec); + return jsString(exec, String::adopt(buffer16)); } - void append(const LChar* str, size_t len) +private: + void append(const LChar* characters, size_t length) { if (m_is8Bit) { - m_okay &= buffer8.tryAppend(str, len); + m_okay &= buffer8.tryAppend(characters, length); return; } - m_okay &= buffer8.tryReserveCapacity(buffer16.size() + len); - for (size_t i = 0; i < len; i++) { - UChar u = str[i]; - m_okay &= buffer16.tryAppend(&u, 1); - } - } - - void append(const UChar* str, size_t len) - { - if (m_is8Bit) - upConvert(); // FIXME: We could check character by character its size. - m_okay &= buffer16.tryAppend(str, len); - } - - void append(const String& str) - { - unsigned length = str.length(); - - if (!length) - return; - - if (m_is8Bit) { - if (str.is8Bit()) { - m_okay &= buffer8.tryAppend(str.characters8(), length); - return; - } - upConvert(); + // FIXME: There must be a more efficient way of doing this. + m_okay &= buffer16.tryReserveCapacity(buffer16.size() + length); + for (size_t i = 0; i < length; i++) { + UChar upconvertedCharacter = characters[i]; + m_okay &= buffer16.tryAppend(&upconvertedCharacter, 1); } - m_okay &= buffer16.tryAppend(str.characters(), length); } void upConvert() @@ -120,23 +112,6 @@ public: m_is8Bit = false; } - JSValue build(ExecState* exec) - { - if (!m_okay) - return throwOutOfMemoryError(exec); - if (m_is8Bit) { - buffer8.shrinkToFit(); - if (!buffer8.data()) - return throwOutOfMemoryError(exec); - return jsString(exec, String::adopt(buffer8)); - } - buffer16.shrinkToFit(); - if (!buffer16.data()) - return throwOutOfMemoryError(exec); - return jsString(exec, String::adopt(buffer16)); - } - -protected: Vector buffer8; Vector buffer16; bool m_okay;