X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/f9bf01c6616d5ddcf65b13b33cedf9e387ff7a63..14957cd040308e3eeec43d26bae5d76da13fcd85:/runtime/JSString.h diff --git a/runtime/JSString.h b/runtime/JSString.h index af03025..668064f 100644 --- a/runtime/JSString.h +++ b/runtime/JSString.h @@ -26,9 +26,10 @@ #include "CallFrame.h" #include "CommonIdentifiers.h" #include "Identifier.h" -#include "JSNumberCell.h" #include "PropertyDescriptor.h" #include "PropertySlot.h" +#include "RopeImpl.h" +#include "Structure.h" namespace JSC { @@ -41,7 +42,6 @@ namespace JSC { JSString* jsSingleCharacterString(JSGlobalData*, UChar); JSString* jsSingleCharacterString(ExecState*, UChar); - JSString* jsSingleCharacterSubstring(JSGlobalData*, const UString&, unsigned offset); JSString* jsSingleCharacterSubstring(ExecState*, const UString&, unsigned offset); JSString* jsSubstring(JSGlobalData*, const UString&, unsigned offset, unsigned length); JSString* jsSubstring(ExecState*, const UString&, unsigned offset, unsigned length); @@ -59,190 +59,209 @@ namespace JSC { JSString* jsOwnedString(JSGlobalData*, const UString&); JSString* jsOwnedString(ExecState*, const UString&); - typedef void (*JSStringFinalizerCallback)(JSString*, void* context); - JSString* jsStringWithFinalizer(ExecState*, const UString&, JSStringFinalizerCallback callback, void* context); - class JS_EXPORTCLASS JSString : public JSCell { public: friend class JIT; friend class JSGlobalData; + friend class SpecializedThunkJIT; + friend struct ThunkHelpers; - // A Rope is a string composed of a set of substrings. - class Rope : public RefCounted { + class RopeBuilder { public: - // A Rope is composed from a set of smaller strings called Fibers. - // Each Fiber in a rope is either UString::Rep or another Rope. - class Fiber { - public: - Fiber() : m_value(0) {} - Fiber(UString::Rep* string) : m_value(reinterpret_cast(string)) {} - Fiber(Rope* rope) : m_value(reinterpret_cast(rope) | 1) {} + RopeBuilder(unsigned fiberCount) + : m_index(0) + , m_rope(RopeImpl::tryCreateUninitialized(fiberCount)) + { + } + + bool isOutOfMemory() { return !m_rope; } + + void append(RopeImpl::Fiber& fiber) + { + ASSERT(m_rope); + m_rope->initializeFiber(m_index, fiber); + } + void append(const UString& string) + { + ASSERT(m_rope); + m_rope->initializeFiber(m_index, string.impl()); + } + void append(JSString* jsString) + { + if (jsString->isRope()) { + for (unsigned i = 0; i < jsString->m_fiberCount; ++i) + append(jsString->m_fibers[i]); + } else + append(jsString->string()); + } + + PassRefPtr release() + { + ASSERT(m_index == m_rope->fiberCount()); + return m_rope.release(); + } - Fiber(void* nonFiber) : m_value(reinterpret_cast(nonFiber)) {} + unsigned length() { return m_rope->length(); } - void deref() + private: + unsigned m_index; + RefPtr m_rope; + }; + + class RopeIterator { + public: + RopeIterator() { } + + RopeIterator(RopeImpl::Fiber* fibers, size_t fiberCount) { - if (isRope()) - rope()->deref(); - else - string()->deref(); + ASSERT(fiberCount); + m_workQueue.append(WorkItem(fibers, fiberCount)); + skipRopes(); } - Fiber& ref() + RopeIterator& operator++() { - if (isString()) - string()->ref(); - else - rope()->ref(); + WorkItem& item = m_workQueue.last(); + ASSERT(!RopeImpl::isRope(item.fibers[item.i])); + if (++item.i == item.fiberCount) + m_workQueue.removeLast(); + skipRopes(); return *this; } - unsigned refAndGetLength() + StringImpl* operator*() { - if (isString()) { - UString::Rep* rep = string(); - return rep->ref()->size(); - } else { - Rope* r = rope(); - r->ref(); - return r->stringLength(); - } + WorkItem& item = m_workQueue.last(); + RopeImpl::Fiber fiber = item.fibers[item.i]; + ASSERT(!RopeImpl::isRope(fiber)); + return static_cast(fiber); } - bool isRope() { return m_value & 1; } - Rope* rope() { return reinterpret_cast(m_value & ~1); } - bool isString() { return !isRope(); } - UString::Rep* string() { return reinterpret_cast(m_value); } + bool operator!=(const RopeIterator& other) const + { + return m_workQueue != other.m_workQueue; + } - void* nonFiber() { return reinterpret_cast(m_value); } private: - intptr_t m_value; - }; + struct WorkItem { + WorkItem(RopeImpl::Fiber* fibers, size_t fiberCount) + : fibers(fibers) + , fiberCount(fiberCount) + , i(0) + { + } - // Creates a Rope comprising of 'ropeLength' Fibers. - // The Rope is constructed in an uninitialized state - initialize must be called for each Fiber in the Rope. - static PassRefPtr createOrNull(unsigned ropeLength) - { - void* allocation; - if (tryFastMalloc(sizeof(Rope) + (ropeLength - 1) * sizeof(Fiber)).getValue(allocation)) - return adoptRef(new (allocation) Rope(ropeLength)); - return 0; - } + bool operator!=(const WorkItem& other) const + { + return fibers != other.fibers || fiberCount != other.fiberCount || i != other.i; + } - ~Rope(); - void destructNonRecursive(); + RopeImpl::Fiber* fibers; + size_t fiberCount; + size_t i; + }; - void append(unsigned &index, Fiber& fiber) - { - m_fibers[index++] = fiber; - m_stringLength += fiber.refAndGetLength(); - } - void append(unsigned &index, const UString& string) - { - UString::Rep* rep = string.rep(); - m_fibers[index++] = Fiber(rep); - m_stringLength += rep->ref()->size(); - } - void append(unsigned& index, JSString* jsString) - { - if (jsString->isRope()) { - for (unsigned i = 0; i < jsString->m_ropeLength; ++i) - append(index, jsString->m_fibers[i]); - } else - append(index, jsString->string()); - } - - unsigned ropeLength() { return m_ropeLength; } - unsigned stringLength() { return m_stringLength; } - Fiber& fibers(unsigned index) { return m_fibers[index]; } + void skipRopes() + { + if (m_workQueue.isEmpty()) + return; + + while (1) { + WorkItem& item = m_workQueue.last(); + RopeImpl::Fiber fiber = item.fibers[item.i]; + if (!RopeImpl::isRope(fiber)) + break; + RopeImpl* rope = static_cast(fiber); + if (++item.i == item.fiberCount) + m_workQueue.removeLast(); + m_workQueue.append(WorkItem(rope->fibers(), rope->fiberCount())); + } + } - private: - Rope(unsigned ropeLength) : m_ropeLength(ropeLength), m_stringLength(0) {} - void* operator new(size_t, void* inPlace) { return inPlace; } - - unsigned m_ropeLength; - unsigned m_stringLength; - Fiber m_fibers[1]; + Vector m_workQueue; }; ALWAYS_INLINE JSString(JSGlobalData* globalData, const UString& value) - : JSCell(globalData->stringStructure.get()) - , m_stringLength(value.size()) + : JSCell(*globalData, globalData->stringStructure.get()) + , m_length(value.length()) , m_value(value) - , m_ropeLength(0) + , m_fiberCount(0) { - Heap::heap(this)->reportExtraMemoryCost(value.cost()); + ASSERT(!m_value.isNull()); + Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost()); } enum HasOtherOwnerType { HasOtherOwner }; JSString(JSGlobalData* globalData, const UString& value, HasOtherOwnerType) - : JSCell(globalData->stringStructure.get()) - , m_stringLength(value.size()) + : JSCell(*globalData, globalData->stringStructure.get()) + , m_length(value.length()) , m_value(value) - , m_ropeLength(0) + , m_fiberCount(0) { + ASSERT(!m_value.isNull()); } - JSString(JSGlobalData* globalData, PassRefPtr value, HasOtherOwnerType) - : JSCell(globalData->stringStructure.get()) - , m_stringLength(value->size()) + JSString(JSGlobalData* globalData, PassRefPtr value, HasOtherOwnerType) + : JSCell(*globalData, globalData->stringStructure.get()) + , m_length(value->length()) , m_value(value) - , m_ropeLength(0) + , m_fiberCount(0) { + ASSERT(!m_value.isNull()); } - JSString(JSGlobalData* globalData, PassRefPtr rope) - : JSCell(globalData->stringStructure.get()) - , m_stringLength(rope->stringLength()) - , m_ropeLength(1) + JSString(JSGlobalData* globalData, PassRefPtr rope) + : JSCell(*globalData, globalData->stringStructure.get()) + , m_length(rope->length()) + , m_fiberCount(1) { - m_fibers[0] = rope.releaseRef(); + m_fibers[0] = rope.leakRef(); } // This constructor constructs a new string by concatenating s1 & s2. - // This should only be called with ropeLength <= 3. - JSString(JSGlobalData* globalData, unsigned ropeLength, JSString* s1, JSString* s2) - : JSCell(globalData->stringStructure.get()) - , m_stringLength(s1->length() + s2->length()) - , m_ropeLength(ropeLength) + // This should only be called with fiberCount <= 3. + JSString(JSGlobalData* globalData, unsigned fiberCount, JSString* s1, JSString* s2) + : JSCell(*globalData, globalData->stringStructure.get()) + , m_length(s1->length() + s2->length()) + , m_fiberCount(fiberCount) { - ASSERT(ropeLength <= s_maxInternalRopeLength); + ASSERT(fiberCount <= s_maxInternalRopeLength); unsigned index = 0; appendStringInConstruct(index, s1); appendStringInConstruct(index, s2); - ASSERT(ropeLength == index); + ASSERT(fiberCount == index); } // This constructor constructs a new string by concatenating s1 & s2. - // This should only be called with ropeLength <= 3. - JSString(JSGlobalData* globalData, unsigned ropeLength, JSString* s1, const UString& u2) - : JSCell(globalData->stringStructure.get()) - , m_stringLength(s1->length() + u2.size()) - , m_ropeLength(ropeLength) + // This should only be called with fiberCount <= 3. + JSString(JSGlobalData* globalData, unsigned fiberCount, JSString* s1, const UString& u2) + : JSCell(*globalData, globalData->stringStructure.get()) + , m_length(s1->length() + u2.length()) + , m_fiberCount(fiberCount) { - ASSERT(ropeLength <= s_maxInternalRopeLength); + ASSERT(fiberCount <= s_maxInternalRopeLength); unsigned index = 0; appendStringInConstruct(index, s1); appendStringInConstruct(index, u2); - ASSERT(ropeLength == index); + ASSERT(fiberCount == index); } // This constructor constructs a new string by concatenating s1 & s2. - // This should only be called with ropeLength <= 3. - JSString(JSGlobalData* globalData, unsigned ropeLength, const UString& u1, JSString* s2) - : JSCell(globalData->stringStructure.get()) - , m_stringLength(u1.size() + s2->length()) - , m_ropeLength(ropeLength) + // This should only be called with fiberCount <= 3. + JSString(JSGlobalData* globalData, unsigned fiberCount, const UString& u1, JSString* s2) + : JSCell(*globalData, globalData->stringStructure.get()) + , m_length(u1.length() + s2->length()) + , m_fiberCount(fiberCount) { - ASSERT(ropeLength <= s_maxInternalRopeLength); + ASSERT(fiberCount <= s_maxInternalRopeLength); unsigned index = 0; appendStringInConstruct(index, u1); appendStringInConstruct(index, s2); - ASSERT(ropeLength == index); + ASSERT(fiberCount == index); } // This constructor constructs a new string by concatenating v1, v2 & v3. - // This should only be called with ropeLength <= 3 ... which since every - // value must require a ropeLength of at least one implies that the length + // This should only be called with fiberCount <= 3 ... which since every + // value must require a fiberCount of at least one implies that the length // for each value must be exactly 1! JSString(ExecState* exec, JSValue v1, JSValue v2, JSValue v3) - : JSCell(exec->globalData().stringStructure.get()) - , m_stringLength(0) - , m_ropeLength(s_maxInternalRopeLength) + : JSCell(exec->globalData(), exec->globalData().stringStructure.get()) + , m_length(0) + , m_fiberCount(s_maxInternalRopeLength) { unsigned index = 0; appendValueInConstructAndIncrementLength(exec, index, v1); @@ -251,28 +270,36 @@ namespace JSC { ASSERT(index == s_maxInternalRopeLength); } - JSString(JSGlobalData* globalData, const UString& value, JSStringFinalizerCallback finalizer, void* context) - : JSCell(globalData->stringStructure.get()) - , m_stringLength(value.size()) - , m_value(value) - , m_ropeLength(0) + // This constructor constructs a new string by concatenating u1 & u2. + JSString(JSGlobalData* globalData, const UString& u1, const UString& u2) + : JSCell(*globalData, globalData->stringStructure.get()) + , m_length(u1.length() + u2.length()) + , m_fiberCount(2) { - // nasty hack because we can't union non-POD types - m_fibers[0] = reinterpret_cast(reinterpret_cast(finalizer)); - m_fibers[1] = context; - Heap::heap(this)->reportExtraMemoryCost(value.cost()); + unsigned index = 0; + appendStringInConstruct(index, u1); + appendStringInConstruct(index, u2); + ASSERT(index <= s_maxInternalRopeLength); + } + + // This constructor constructs a new string by concatenating u1, u2 & u3. + JSString(JSGlobalData* globalData, const UString& u1, const UString& u2, const UString& u3) + : JSCell(*globalData, globalData->stringStructure.get()) + , m_length(u1.length() + u2.length() + u3.length()) + , m_fiberCount(s_maxInternalRopeLength) + { + unsigned index = 0; + appendStringInConstruct(index, u1); + appendStringInConstruct(index, u2); + appendStringInConstruct(index, u3); + ASSERT(index <= s_maxInternalRopeLength); } ~JSString() { ASSERT(vptr() == JSGlobalData::jsStringVPtr); - for (unsigned i = 0; i < m_ropeLength; ++i) - m_fibers[i].deref(); - - if (!m_ropeLength && m_fibers[0].nonFiber()) { - JSStringFinalizerCallback finalizer = reinterpret_cast(m_fibers[0].nonFiber()); - finalizer(this, m_fibers[1].nonFiber()); - } + for (unsigned i = 0; i < m_fiberCount; ++i) + RopeImpl::deref(m_fibers[i]); } const UString& value(ExecState* exec) const @@ -281,43 +308,58 @@ namespace JSC { resolveRope(exec); return m_value; } - const UString tryGetValue() const + const UString& tryGetValue() const { if (isRope()) - UString(); + resolveRope(0); return m_value; } - unsigned length() { return m_stringLength; } + unsigned length() { return m_length; } bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); bool getStringPropertyDescriptor(ExecState*, const Identifier& propertyName, PropertyDescriptor&); - bool canGetIndex(unsigned i) { return i < m_stringLength; } + bool canGetIndex(unsigned i) { return i < m_length; } JSString* getIndex(ExecState*, unsigned); + JSString* getIndexSlowCase(ExecState*, unsigned); + + JSValue replaceCharacter(ExecState*, UChar, const UString& replacement); - static PassRefPtr createStructure(JSValue proto) { return Structure::create(proto, TypeInfo(StringType, OverridesGetOwnPropertySlot | NeedsThisConversion), AnonymousSlotCount); } + static Structure* createStructure(JSGlobalData& globalData, JSValue proto) + { + return Structure::create(globalData, proto, TypeInfo(StringType, OverridesGetOwnPropertySlot | NeedsThisConversion), AnonymousSlotCount, &s_info); + } + + static const ClassInfo s_info; private: - enum VPtrStealingHackType { VPtrStealingHack }; JSString(VPtrStealingHackType) - : JSCell(0) - , m_ropeLength(0) + : JSCell(VPtrStealingHack) + , m_fiberCount(0) { } void resolveRope(ExecState*) const; + void resolveRopeSlowCase(ExecState*, UChar*) const; + void outOfMemory(ExecState*) const; + JSString* substringFromRope(ExecState*, unsigned offset, unsigned length); void appendStringInConstruct(unsigned& index, const UString& string) { - m_fibers[index++] = Rope::Fiber(string.rep()->ref()); + StringImpl* impl = string.impl(); + impl->ref(); + m_fibers[index++] = impl; } void appendStringInConstruct(unsigned& index, JSString* jsString) { if (jsString->isRope()) { - for (unsigned i = 0; i < jsString->m_ropeLength; ++i) - m_fibers[index++] = jsString->m_fibers[i].ref(); + for (unsigned i = 0; i < jsString->m_fiberCount; ++i) { + RopeImpl::Fiber fiber = jsString->m_fibers[i]; + fiber->ref(); + m_fibers[index++] = fiber; + } } else appendStringInConstruct(index, jsString->string()); } @@ -325,15 +367,17 @@ namespace JSC { void appendValueInConstructAndIncrementLength(ExecState* exec, unsigned& index, JSValue v) { if (v.isString()) { - ASSERT(asCell(v)->isString()); - JSString* s = static_cast(asCell(v)); - ASSERT(s->ropeLength() == 1); + ASSERT(v.asCell()->isString()); + JSString* s = static_cast(v.asCell()); + ASSERT(s->fiberCount() == 1); appendStringInConstruct(index, s); - m_stringLength += s->length(); + m_length += s->length(); } else { UString u(v.toString(exec)); - m_fibers[index++] = Rope::Fiber(u.rep()->ref()); - m_stringLength += u.size(); + StringImpl* impl = u.impl(); + impl->ref(); + m_fibers[index++] = impl; + m_length += u.length(); } } @@ -341,12 +385,10 @@ namespace JSC { virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value); virtual bool toBoolean(ExecState*) const; virtual double toNumber(ExecState*) const; - virtual JSObject* toObject(ExecState*) const; + virtual JSObject* toObject(ExecState*, JSGlobalObject*) const; virtual UString toString(ExecState*) const; virtual JSObject* toThisObject(ExecState*) const; - virtual UString toThisString(ExecState*) const; - virtual JSString* toThisJSString(ExecState*); // Actually getPropertySlot, not getOwnPropertySlot (see JSCell). virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); @@ -355,22 +397,22 @@ namespace JSC { static const unsigned s_maxInternalRopeLength = 3; - // A string is represented either by a UString or a Rope. - unsigned m_stringLength; + // A string is represented either by a UString or a RopeImpl. + unsigned m_length; mutable UString m_value; - mutable unsigned m_ropeLength; - mutable Rope::Fiber m_fibers[s_maxInternalRopeLength]; + mutable unsigned m_fiberCount; + mutable FixedArray m_fibers; - bool isRope() const { return m_ropeLength; } + bool isRope() const { return m_fiberCount; } UString& string() { ASSERT(!isRope()); return m_value; } - unsigned ropeLength() { return m_ropeLength ? m_ropeLength : 1; } + unsigned fiberCount() { return m_fiberCount ? m_fiberCount : 1; } friend JSValue jsString(ExecState* exec, JSString* s1, JSString* s2); friend JSValue jsString(ExecState* exec, const UString& u1, JSString* s2); friend JSValue jsString(ExecState* exec, JSString* s1, const UString& u2); friend JSValue jsString(ExecState* exec, Register* strings, unsigned count); - friend JSValue jsString(ExecState* exec, JSValue thisValue, const ArgList& args); - friend JSString* jsStringWithFinalizer(ExecState*, const UString&, JSStringFinalizerCallback callback, void* context); + friend JSValue jsString(ExecState* exec, JSValue thisValue); + friend JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsigned length); }; JSString* asString(JSValue); @@ -387,8 +429,8 @@ namespace JSC { inline JSString* asString(JSValue value) { - ASSERT(asCell(value)->isString()); - return static_cast(asCell(value)); + ASSERT(value.asCell()->isString()); + return static_cast(value.asCell()); } inline JSString* jsEmptyString(JSGlobalData* globalData) @@ -398,18 +440,19 @@ namespace JSC { inline JSString* jsSingleCharacterString(JSGlobalData* globalData, UChar c) { - if (c <= 0xFF) + if (c <= maxSingleCharacterString) return globalData->smallStrings.singleCharacterString(globalData, c); return fixupVPtr(globalData, new (globalData) JSString(globalData, UString(&c, 1))); } - inline JSString* jsSingleCharacterSubstring(JSGlobalData* globalData, const UString& s, unsigned offset) + inline JSString* jsSingleCharacterSubstring(ExecState* exec, const UString& s, unsigned offset) { - ASSERT(offset < static_cast(s.size())); - UChar c = s.data()[offset]; - if (c <= 0xFF) + JSGlobalData* globalData = &exec->globalData(); + ASSERT(offset < static_cast(s.length())); + UChar c = s.characters()[offset]; + if (c <= maxSingleCharacterString) return globalData->smallStrings.singleCharacterString(globalData, c); - return fixupVPtr(globalData, new (globalData) JSString(globalData, UString(UString::Rep::create(s.rep(), offset, 1)))); + return fixupVPtr(globalData, new (globalData) JSString(globalData, UString(StringImpl::create(s.impl(), offset, 1)))); } inline JSString* jsNontrivialString(JSGlobalData* globalData, const char* s) @@ -422,59 +465,68 @@ namespace JSC { inline JSString* jsNontrivialString(JSGlobalData* globalData, const UString& s) { - ASSERT(s.size() > 1); + ASSERT(s.length() > 1); return fixupVPtr(globalData, new (globalData) JSString(globalData, s)); } inline JSString* JSString::getIndex(ExecState* exec, unsigned i) { ASSERT(canGetIndex(i)); - return jsSingleCharacterSubstring(&exec->globalData(), value(exec), i); + if (isRope()) + return getIndexSlowCase(exec, i); + ASSERT(i < m_value.length()); + return jsSingleCharacterSubstring(exec, m_value, i); } inline JSString* jsString(JSGlobalData* globalData, const UString& s) { - int size = s.size(); + int size = s.length(); if (!size) return globalData->smallStrings.emptyString(globalData); if (size == 1) { - UChar c = s.data()[0]; - if (c <= 0xFF) + UChar c = s.characters()[0]; + if (c <= maxSingleCharacterString) return globalData->smallStrings.singleCharacterString(globalData, c); } return fixupVPtr(globalData, new (globalData) JSString(globalData, s)); } - inline JSString* jsStringWithFinalizer(ExecState* exec, const UString& s, JSStringFinalizerCallback callback, void* context) + inline JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsigned length) { - ASSERT(s.size() && (s.size() > 1 || s.data()[0] > 0xFF)); + ASSERT(offset <= static_cast(s->length())); + ASSERT(length <= static_cast(s->length())); + ASSERT(offset + length <= static_cast(s->length())); JSGlobalData* globalData = &exec->globalData(); - return fixupVPtr(globalData, new (globalData) JSString(globalData, s, callback, context)); + if (!length) + return globalData->smallStrings.emptyString(globalData); + if (s->isRope()) + return s->substringFromRope(exec, offset, length); + return jsSubstring(globalData, s->m_value, offset, length); } inline JSString* jsSubstring(JSGlobalData* globalData, const UString& s, unsigned offset, unsigned length) { - ASSERT(offset <= static_cast(s.size())); - ASSERT(length <= static_cast(s.size())); - ASSERT(offset + length <= static_cast(s.size())); + ASSERT(offset <= static_cast(s.length())); + ASSERT(length <= static_cast(s.length())); + ASSERT(offset + length <= static_cast(s.length())); if (!length) return globalData->smallStrings.emptyString(globalData); if (length == 1) { - UChar c = s.data()[offset]; - if (c <= 0xFF) + UChar c = s.characters()[offset]; + if (c <= maxSingleCharacterString) return globalData->smallStrings.singleCharacterString(globalData, c); } - return fixupVPtr(globalData, new (globalData) JSString(globalData, UString(UString::Rep::create(s.rep(), offset, length)), JSString::HasOtherOwner)); + return fixupVPtr(globalData, new (globalData) JSString(globalData, UString(StringImpl::create(s.impl(), offset, length)), JSString::HasOtherOwner)); } inline JSString* jsOwnedString(JSGlobalData* globalData, const UString& s) { - int size = s.size(); + int size = s.length(); if (!size) return globalData->smallStrings.emptyString(globalData); if (size == 1) { - UChar c = s.data()[0]; - if (c <= 0xFF) + UChar c = s.characters()[0]; + if (c <= maxSingleCharacterString) return globalData->smallStrings.singleCharacterString(globalData, c); } return fixupVPtr(globalData, new (globalData) JSString(globalData, s, JSString::HasOtherOwner)); @@ -483,7 +535,6 @@ namespace JSC { 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* jsSingleCharacterSubstring(ExecState* exec, const UString& s, unsigned offset) { return jsSingleCharacterSubstring(&exec->globalData(), s, offset); } 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); } @@ -492,14 +543,14 @@ namespace JSC { ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) { if (propertyName == exec->propertyNames().length) { - slot.setValue(jsNumber(exec, m_stringLength)); + slot.setValue(jsNumber(m_length)); return true; } bool isStrictUInt32; - unsigned i = propertyName.toStrictUInt32(&isStrictUInt32); - if (isStrictUInt32 && i < m_stringLength) { - slot.setValue(jsSingleCharacterSubstring(exec, value(exec), i)); + unsigned i = propertyName.toUInt32(isStrictUInt32); + if (isStrictUInt32 && i < m_length) { + slot.setValue(getIndex(exec, i)); return true; } @@ -508,8 +559,8 @@ namespace JSC { ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot) { - if (propertyName < m_stringLength) { - slot.setValue(jsSingleCharacterSubstring(exec, value(exec), propertyName)); + if (propertyName < m_length) { + slot.setValue(getIndex(exec, propertyName)); return true; } @@ -520,11 +571,6 @@ namespace JSC { // --- JSValue inlines ---------------------------- - inline JSString* JSValue::toThisJSString(ExecState* exec) - { - return isCell() ? asCell()->toThisJSString(exec) : jsString(exec, toString(exec)); - } - inline UString JSValue::toString(ExecState* exec) const { if (isString()) @@ -547,8 +593,7 @@ namespace JSC { inline UString JSValue::toPrimitiveString(ExecState* exec) const { - if (isString()) - return static_cast(asCell())->value(exec); + ASSERT(!isString()); if (isInt32()) return exec->globalData().numericStrings.add(asInt32()); if (isDouble())