- inline JSString* jsEmptyString(ExecState* exec) { return jsEmptyString(&exec->globalData()); }
- inline JSString* jsString(ExecState* exec, const UString& s) { return jsString(&exec->globalData(), s); }
- inline JSString* jsSingleCharacterString(ExecState* exec, UChar c) { return jsSingleCharacterString(&exec->globalData(), c); }
- inline JSString* jsSubstring(ExecState* exec, const UString& s, unsigned offset, unsigned length) { return jsSubstring(&exec->globalData(), s, offset, length); }
- inline JSString* jsNontrivialString(ExecState* exec, const UString& s) { return jsNontrivialString(&exec->globalData(), s); }
- inline JSString* jsNontrivialString(ExecState* exec, const char* s) { return jsNontrivialString(&exec->globalData(), s); }
- inline JSString* jsOwnedString(ExecState* exec, const UString& s) { return jsOwnedString(&exec->globalData(), s); }
+ inline JSRopeString* jsStringBuilder(VM* vm)
+ {
+ return JSRopeString::createNull(*vm);
+ }
+
+ inline JSString* jsEmptyString(ExecState* exec) { return jsEmptyString(&exec->vm()); }
+ inline JSString* jsString(ExecState* exec, const String& s) { return jsString(&exec->vm(), s); }
+ inline JSString* jsSingleCharacterString(ExecState* exec, UChar c) { return jsSingleCharacterString(&exec->vm(), c); }
+ inline JSString* jsSubstring8(ExecState* exec, const String& s, unsigned offset, unsigned length) { return jsSubstring8(&exec->vm(), s, offset, length); }
+ inline JSString* jsSubstring(ExecState* exec, const String& s, unsigned offset, unsigned length) { return jsSubstring(&exec->vm(), s, offset, length); }
+ inline JSString* jsNontrivialString(ExecState* exec, const String& s) { return jsNontrivialString(&exec->vm(), s); }
+ inline JSString* jsOwnedString(ExecState* exec, const String& s) { return jsOwnedString(&exec->vm(), s); }
+
+ JS_EXPORT_PRIVATE JSString* jsStringWithCacheSlowCase(VM&, StringImpl&);
+
+ ALWAYS_INLINE JSString* jsStringWithCache(ExecState* exec, const String& s)
+ {
+ VM& vm = exec->vm();
+ StringImpl* stringImpl = s.impl();
+ if (!stringImpl || !stringImpl->length())
+ return jsEmptyString(&vm);
+
+ if (stringImpl->length() == 1) {
+ UChar singleCharacter = (*stringImpl)[0u];
+ if (singleCharacter <= maxSingleCharacterString)
+ return vm.smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
+ }
+
+ if (JSString* lastCachedString = vm.lastCachedString.get()) {
+ if (lastCachedString->tryGetValueImpl() == stringImpl)
+ return lastCachedString;
+ }
+
+ return jsStringWithCacheSlowCase(vm, *stringImpl);
+ }
+
+ ALWAYS_INLINE JSString* jsStringWithCache(ExecState* exec, const AtomicString& s)
+ {
+ return jsStringWithCache(exec, s.string());
+ }