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/JSString.cpp

    r53371 r54804  
    3232namespace JSC {
    3333
    34 void JSString::Rope::destructNonRecursive()
     34void Rope::destructNonRecursive()
    3535{
    3636    Vector<Rope*, 32> workQueue;
     
    3838
    3939    while (true) {
    40         unsigned length = rope->ropeLength();
     40        unsigned length = rope->fiberCount();
    4141        for (unsigned i = 0; i < length; ++i) {
    4242            Fiber& fiber = rope->fibers(i);
     
    6262}
    6363
    64 JSString::Rope::~Rope()
     64Rope::~Rope()
    6565{
    6666    destructNonRecursive();
     
    8383    // Allocate the buffer to hold the final string, position initially points to the end.
    8484    UChar* buffer;
    85     if (PassRefPtr<UStringImpl> newImpl = UStringImpl::tryCreateUninitialized(m_stringLength, buffer))
     85    if (PassRefPtr<UStringImpl> newImpl = UStringImpl::tryCreateUninitialized(m_length, buffer))
    8686        m_value = newImpl;
    8787    else {
    88         for (unsigned i = 0; i < m_ropeLength; ++i) {
     88        for (unsigned i = 0; i < m_fiberCount; ++i) {
    8989            m_fibers[i].deref();
    9090            m_fibers[i] = static_cast<void*>(0);
    9191        }
    92         m_ropeLength = 0;
     92        m_fiberCount = 0;
    9393        ASSERT(!isRope());
    9494        ASSERT(m_value == UString());
     
    9696        return;
    9797    }
    98     UChar* position = buffer + m_stringLength;
     98    UChar* position = buffer + m_length;
    9999
    100100    // Start with the current Rope.
    101101    Vector<Rope::Fiber, 32> workQueue;
    102102    Rope::Fiber currentFiber;
    103     for (unsigned i = 0; i < (m_ropeLength - 1); ++i)
     103    for (unsigned i = 0; i < (m_fiberCount - 1); ++i)
    104104        workQueue.append(m_fibers[i]);
    105     currentFiber = m_fibers[m_ropeLength - 1];
     105    currentFiber = m_fibers[m_fiberCount - 1];
    106106    while (true) {
    107107        if (currentFiber.isRope()) {
     
    109109            // Copy the contents of the current rope into the workQueue, with the last item in 'currentFiber'
    110110            // (we will be working backwards over the rope).
    111             unsigned ropeLengthMinusOne = rope->ropeLength() - 1;
    112             for (unsigned i = 0; i < ropeLengthMinusOne; ++i)
     111            unsigned fiberCountMinusOne = rope->fiberCount() - 1;
     112            for (unsigned i = 0; i < fiberCountMinusOne; ++i)
    113113                workQueue.append(rope->fibers(i));
    114             currentFiber = rope->fibers(ropeLengthMinusOne);
     114            currentFiber = rope->fibers(fiberCountMinusOne);
    115115        } else {
    116116            UString::Rep* string = currentFiber.string();
     
    123123                // Create a string from the UChar buffer, clear the rope RefPtr.
    124124                ASSERT(buffer == position);
    125                 for (unsigned i = 0; i < m_ropeLength; ++i) {
     125                for (unsigned i = 0; i < m_fiberCount; ++i) {
    126126                    m_fibers[i].deref();
    127127                    m_fibers[i] = static_cast<void*>(0);
    128128                }
    129                 m_ropeLength = 0;
     129                m_fiberCount = 0;
    130130
    131131                ASSERT(!isRope());
     
    154154bool JSString::toBoolean(ExecState*) const
    155155{
    156     return m_stringLength;
     156    return m_length;
    157157}
    158158
     
    216216{
    217217    if (propertyName == exec->propertyNames().length) {
    218         descriptor.setDescriptor(jsNumber(exec, m_stringLength), DontEnum | DontDelete | ReadOnly);
     218        descriptor.setDescriptor(jsNumber(exec, m_length), DontEnum | DontDelete | ReadOnly);
    219219        return true;
    220220    }
     
    222222    bool isStrictUInt32;
    223223    unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
    224     if (isStrictUInt32 && i < m_stringLength) {
     224    if (isStrictUInt32 && i < m_length) {
    225225        descriptor.setDescriptor(jsSingleCharacterSubstring(exec, value(exec), i), DontDelete | ReadOnly);
    226226        return true;
Note: See TracChangeset for help on using the changeset viewer.