Ignore:
Timestamp:
Feb 15, 2010, 5:32:06 PM (15 years ago)
Author:
[email protected]
Message:

Some general Rope related refactoring.

Reviewed by Oliver Hunt.

Rename Rope::m_ropeLength to m_fiberCount, to be more descriptive.
Rename Rope::m_stringLength to simply m_length (since this is the
more conventional name for the length of a string). Move append
behaviour out into a new RopeBuilder class, so that Rope no longer
needs any knowledge of the JSString or UString implementation.

Make Rope no longer be nested within JSString.
(Rope now no-longer need reside within JSString.h, but leaving
the change of moving this out to a different header as a separate
change from these renames).

(JSC::JIT::privateCompileCTIMachineTrampolines):

  • runtime/JSString.cpp:

(JSC::Rope::destructNonRecursive):
(JSC::Rope::~Rope):
(JSC::JSString::resolveRope):
(JSC::JSString::toBoolean):
(JSC::JSString::getStringPropertyDescriptor):

  • runtime/JSString.h:

(JSC::Rope::Fiber::Fiber):
(JSC::Rope::Fiber::deref):
(JSC::Rope::Fiber::ref):
(JSC::Rope::Fiber::refAndGetLength):
(JSC::Rope::Fiber::isRope):
(JSC::Rope::Fiber::rope):
(JSC::Rope::Fiber::isString):
(JSC::Rope::Fiber::string):
(JSC::Rope::Fiber::nonFiber):
(JSC::Rope::tryCreateUninitialized):
(JSC::Rope::append):
(JSC::Rope::fiberCount):
(JSC::Rope::length):
(JSC::Rope::fibers):
(JSC::Rope::Rope):
(JSC::Rope::operator new):
(JSC::):
(JSC::RopeBuilder::JSString):
(JSC::RopeBuilder::~JSString):
(JSC::RopeBuilder::length):
(JSC::RopeBuilder::canGetIndex):
(JSC::RopeBuilder::appendStringInConstruct):
(JSC::RopeBuilder::appendValueInConstructAndIncrementLength):
(JSC::RopeBuilder::isRope):
(JSC::RopeBuilder::fiberCount):
(JSC::JSString::getStringPropertySlot):

  • runtime/Operations.h:

(JSC::jsString):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Operations.h

    r54394 r54804  
    4343            return s1;
    4444
    45         unsigned ropeLength = s1->ropeLength() + s2->ropeLength();
     45        unsigned fiberCount = s1->fiberCount() + s2->fiberCount();
    4646        JSGlobalData* globalData = &exec->globalData();
    4747
    48         if (ropeLength <= JSString::s_maxInternalRopeLength)
    49             return new (globalData) JSString(globalData, ropeLength, s1, s2);
    50 
    51         unsigned index = 0;
    52         RefPtr<JSString::Rope> rope = JSString::Rope::createOrNull(ropeLength);
    53         if (UNLIKELY(!rope))
     48        if (fiberCount <= JSString::s_maxInternalRopeLength)
     49            return new (globalData) JSString(globalData, fiberCount, s1, s2);
     50
     51        JSString::RopeBuilder ropeBuilder(fiberCount);
     52        if (UNLIKELY(ropeBuilder.isOutOfMemory()))
    5453            return throwOutOfMemoryError(exec);
    55         rope->append(index, s1);
    56         rope->append(index, s2);
    57         ASSERT(index == ropeLength);
    58         return new (globalData) JSString(globalData, rope.release());
     54        ropeBuilder.append(s1);
     55        ropeBuilder.append(s2);
     56        return new (globalData) JSString(globalData, ropeBuilder.release());
    5957    }
    6058
    6159    ALWAYS_INLINE JSValue jsString(ExecState* exec, const UString& u1, JSString* s2)
    6260    {
    63         unsigned ropeLength = 1 + s2->ropeLength();
     61        unsigned fiberCount = 1 + s2->fiberCount();
    6462        JSGlobalData* globalData = &exec->globalData();
    6563
    66         if (ropeLength <= JSString::s_maxInternalRopeLength)
    67             return new (globalData) JSString(globalData, ropeLength, u1, s2);
    68 
    69         unsigned index = 0;
    70         RefPtr<JSString::Rope> rope = JSString::Rope::createOrNull(ropeLength);
    71         if (UNLIKELY(!rope))
     64        if (fiberCount <= JSString::s_maxInternalRopeLength)
     65            return new (globalData) JSString(globalData, fiberCount, u1, s2);
     66
     67        JSString::RopeBuilder ropeBuilder(fiberCount);
     68        if (UNLIKELY(ropeBuilder.isOutOfMemory()))
    7269            return throwOutOfMemoryError(exec);
    73         rope->append(index, u1);
    74         rope->append(index, s2);
    75         ASSERT(index == ropeLength);
    76         return new (globalData) JSString(globalData, rope.release());
     70        ropeBuilder.append(u1);
     71        ropeBuilder.append(s2);
     72        return new (globalData) JSString(globalData, ropeBuilder.release());
    7773    }
    7874
    7975    ALWAYS_INLINE JSValue jsString(ExecState* exec, JSString* s1, const UString& u2)
    8076    {
    81         unsigned ropeLength = s1->ropeLength() + 1;
     77        unsigned fiberCount = s1->fiberCount() + 1;
    8278        JSGlobalData* globalData = &exec->globalData();
    8379
    84         if (ropeLength <= JSString::s_maxInternalRopeLength)
    85             return new (globalData) JSString(globalData, ropeLength, s1, u2);
    86 
    87         unsigned index = 0;
    88         RefPtr<JSString::Rope> rope = JSString::Rope::createOrNull(ropeLength);
    89         if (UNLIKELY(!rope))
     80        if (fiberCount <= JSString::s_maxInternalRopeLength)
     81            return new (globalData) JSString(globalData, fiberCount, s1, u2);
     82
     83        JSString::RopeBuilder ropeBuilder(fiberCount);
     84        if (UNLIKELY(ropeBuilder.isOutOfMemory()))
    9085            return throwOutOfMemoryError(exec);
    91         rope->append(index, s1);
    92         rope->append(index, u2);
    93         ASSERT(index == ropeLength);
    94         return new (globalData) JSString(globalData, rope.release());
     86        ropeBuilder.append(s1);
     87        ropeBuilder.append(u2);
     88        return new (globalData) JSString(globalData, ropeBuilder.release());
    9589    }
    9690
     
    9993        ASSERT(count >= 3);
    10094
    101         unsigned ropeLength = 0;
     95        unsigned fiberCount = 0;
    10296        for (unsigned i = 0; i < count; ++i) {
    10397            JSValue v = strings[i].jsValue();
    10498            if (LIKELY(v.isString()))
    105                 ropeLength += asString(v)->ropeLength();
     99                fiberCount += asString(v)->fiberCount();
    106100            else
    107                 ++ropeLength;
     101                ++fiberCount;
    108102        }
    109103
    110104        JSGlobalData* globalData = &exec->globalData();
    111         if (ropeLength == 3)
     105        if (fiberCount == 3)
    112106            return new (globalData) JSString(exec, strings[0].jsValue(), strings[1].jsValue(), strings[2].jsValue());
    113107
    114         RefPtr<JSString::Rope> rope = JSString::Rope::createOrNull(ropeLength);
    115         if (UNLIKELY(!rope))
     108        JSString::RopeBuilder ropeBuilder(fiberCount);
     109        if (UNLIKELY(ropeBuilder.isOutOfMemory()))
    116110            return throwOutOfMemoryError(exec);
    117111
    118         unsigned index = 0;
    119112        for (unsigned i = 0; i < count; ++i) {
    120113            JSValue v = strings[i].jsValue();
    121114            if (LIKELY(v.isString()))
    122                 rope->append(index, asString(v));
     115                ropeBuilder.append(asString(v));
    123116            else
    124                 rope->append(index, v.toString(exec));
    125         }
    126 
    127         ASSERT(index == ropeLength);
    128         return new (globalData) JSString(globalData, rope.release());
     117                ropeBuilder.append(v.toString(exec));
     118        }
     119
     120        return new (globalData) JSString(globalData, ropeBuilder.release());
    129121    }
    130122
    131123    ALWAYS_INLINE JSValue jsString(ExecState* exec, JSValue thisValue, const ArgList& args)
    132124    {
    133         unsigned ropeLength = 0;
     125        unsigned fiberCount = 0;
    134126        if (LIKELY(thisValue.isString()))
    135             ropeLength += asString(thisValue)->ropeLength();
     127            fiberCount += asString(thisValue)->fiberCount();
    136128        else
    137             ++ropeLength;
     129            ++fiberCount;
    138130        for (unsigned i = 0; i < args.size(); ++i) {
    139131            JSValue v = args.at(i);
    140132            if (LIKELY(v.isString()))
    141                 ropeLength += asString(v)->ropeLength();
     133                fiberCount += asString(v)->fiberCount();
    142134            else
    143                 ++ropeLength;
    144         }
    145 
    146         RefPtr<JSString::Rope> rope = JSString::Rope::createOrNull(ropeLength);
    147         if (UNLIKELY(!rope))
     135                ++fiberCount;
     136        }
     137
     138        JSString::RopeBuilder ropeBuilder(fiberCount);
     139        if (UNLIKELY(ropeBuilder.isOutOfMemory()))
    148140            return throwOutOfMemoryError(exec);
    149141
    150         unsigned index = 0;
    151142        if (LIKELY(thisValue.isString()))
    152             rope->append(index, asString(thisValue));
     143            ropeBuilder.append(asString(thisValue));
    153144        else
    154             rope->append(index, thisValue.toString(exec));
     145            ropeBuilder.append(thisValue.toString(exec));
    155146        for (unsigned i = 0; i < args.size(); ++i) {
    156147            JSValue v = args.at(i);
    157148            if (LIKELY(v.isString()))
    158                 rope->append(index, asString(v));
     149                ropeBuilder.append(asString(v));
    159150            else
    160                 rope->append(index, v.toString(exec));
    161         }
    162         ASSERT(index == ropeLength);
     151                ropeBuilder.append(v.toString(exec));
     152        }
    163153
    164154        JSGlobalData* globalData = &exec->globalData();
    165         return new (globalData) JSString(globalData, rope.release());
     155        return new (globalData) JSString(globalData, ropeBuilder.release());
    166156    }
    167157
Note: See TracChangeset for help on using the changeset viewer.