Ignore:
Timestamp:
May 11, 2010, 11:42:46 AM (15 years ago)
Author:
[email protected]
Message:

Start using ropes in String.prototype.replace.

Reviewed by Oliver Hunt and Darin Adler.

1%-1.5% speedup on SunSpider.

  • runtime/JSString.cpp:

(JSC::JSString::resolveRope): Updated for RopeImpl refactoring.

(JSC::JSString::replaceCharacter): Added a replaceCharacter function, which creates
a rope for the resulting replacement.

  • runtime/JSString.h: A few changes here:

(JSC::):
(JSC::RopeBuilder::RopeIterator::RopeIterator):
(JSC::RopeBuilder::RopeIterator::operator++):
(JSC::RopeBuilder::RopeIterator::operator*):
(JSC::RopeBuilder::RopeIterator::operator!=):
(JSC::RopeBuilder::RopeIterator::WorkItem::WorkItem):
(JSC::RopeBuilder::RopeIterator::WorkItem::operator!=):
(JSC::RopeBuilder::RopeIterator::skipRopes): Created a RopeIterator abstraction.
We use this to do a substring find without having to resolve the rope.
(We could use this iterator when resolving ropes, too, but resolving
ropes backwards is usually more efficient.)

(JSC::RopeBuilder::JSString): Added constructors for 2 & 3 UStrings.

(JSC::RopeBuilder::appendValueInConstructAndIncrementLength):
(JSC::RopeBuilder::size): Updated for RopeImpl refactoring.

  • runtime/Operations.h: Updated for RopeImpl refactoring.

(JSC::jsString): Added jsString functions for 2 & 3 UStrings.

  • runtime/RopeImpl.cpp:

(JSC::RopeImpl::derefFibersNonRecursive):

  • runtime/RopeImpl.h:

(JSC::RopeImpl::initializeFiber):
(JSC::RopeImpl::size):
(JSC::RopeImpl::fibers):
(JSC::RopeImpl::deref):
(JSC::RopeImpl::RopeImpl): A little refactoring to make this patch easier:
Moved statics to the top of the class; put multi-statement functions on
multiple lines; renamed "fiberCount" to "size" to match other collections;
changed the "fibers" accessor to return the fibers buffer, instead of an
item in the buffer, to make iteration easier.

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncReplace): Don't resolve a rope unless we need to. Do
use our new replaceCharacter function if possible. Do use a rope to
represent splicing three strings together.

File:
1 edited

Legend:

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

    r57932 r59161  
    4747    }
    4848
    49     void initializeFiber(unsigned &index, Fiber fiber)
    50     {
    51         m_fibers[index++] = fiber;
    52         fiber->ref();
    53         m_length += fiber->length();
    54     }
    55 
    56     unsigned fiberCount() { return m_fiberCount; }
    57     Fiber& fibers(unsigned index) { return m_fibers[index]; }
    58 
    59     ALWAYS_INLINE void deref() { m_refCountAndFlags -= s_refCountIncrement; if (!(m_refCountAndFlags & s_refCountMask)) destructNonRecursive(); }
    60 
    6149    static bool isRope(Fiber fiber)
    6250    {
     
    7260    }
    7361
     62    void initializeFiber(unsigned &index, Fiber fiber)
     63    {
     64        m_fibers[index++] = fiber;
     65        fiber->ref();
     66        m_length += fiber->length();
     67    }
     68
     69    unsigned fiberCount() { return m_size; }
     70    Fiber* fibers() { return m_fibers; }
     71
     72    ALWAYS_INLINE void deref()
     73    {
     74        m_refCountAndFlags -= s_refCountIncrement;
     75        if (!(m_refCountAndFlags & s_refCountMask))
     76            destructNonRecursive();
     77    }
     78
    7479private:
    75     RopeImpl(unsigned fiberCount) : StringImplBase(ConstructNonStringImpl), m_fiberCount(fiberCount) {}
     80    RopeImpl(unsigned fiberCount)
     81        : StringImplBase(ConstructNonStringImpl)
     82        , m_size(fiberCount)
     83    {
     84    }
    7685
    7786    void destructNonRecursive();
     
    8089    bool hasOneRef() { return (m_refCountAndFlags & s_refCountMask) == s_refCountIncrement; }
    8190
    82     unsigned m_fiberCount;
     91    unsigned m_size;
    8392    Fiber m_fibers[1];
    8493};
Note: See TracChangeset for help on using the changeset viewer.