Ignore:
Timestamp:
Jan 13, 2010, 5:20:52 PM (15 years ago)
Author:
[email protected]
Message:

Rubber stamped by Sam Weinig & Darin Adler.

Three quick fixes to UStringImpl.

  • The destroy() method can be switched back to a normal destructor; since we've switched the way we protect static strings to be using an odd ref-count the destroy() won't abort.
  • The cost() calculation logic was wrong. If you have multiple JSStrings wrapping substrings of a base string, they would each report the full cost of the base string to the heap. Instead we should only be reporting once for the base string.
  • Remove the overloaded new operator calling fastMalloc, replace this with a 'using' to pick up the implementation from the parent class.

(JSC::UStringImpl::~UStringImpl):

  • runtime/UStringImpl.h:

(JSC::UStringImpl::cost):
(JSC::UStringImpl::deref):

File:
1 edited

Legend:

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

    r52856 r53221  
    129129    size_t cost()
    130130    {
    131         UStringImpl* base = bufferOwnerString();
     131        // For substrings, return the cost of the base string.
     132        if (bufferOwnership() == BufferSubstring)
     133            return m_dataBuffer.asPtr<UStringImpl*>()->cost();
     134
    132135        if (m_dataBuffer & s_reportedCostBit)
    133136            return 0;
    134137        m_dataBuffer |= s_reportedCostBit;
    135         return base->m_length;
     138        return m_length;
    136139    }
    137140    unsigned hash() const { if (!m_hash) m_hash = computeHash(data(), m_length); return m_hash; }
     
    142145
    143146    UStringImpl* ref() { m_refCount += s_refCountIncrement; return this; }
    144     ALWAYS_INLINE void deref() { if (!(m_refCount -= s_refCountIncrement)) destroy(); }
     147    ALWAYS_INLINE void deref() { if (!(m_refCount -= s_refCountIncrement)) delete this; }
    145148
    146149    static WTF::PossiblyNull<UChar*> allocChars(size_t length)
     
    244247    }
    245248
    246     void* operator new(size_t size) { return fastMalloc(size); }
     249    using Noncopyable::operator new;
    247250    void* operator new(size_t, void* inPlace) { return inPlace; }
     251
     252    ~UStringImpl();
    248253
    249254    // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
     
    257262    static const int s_staticRefCountInitialValue = 1;
    258263
    259     void destroy();
    260264    UStringImpl* bufferOwnerString() { return (bufferOwnership() == BufferSubstring) ? m_dataBuffer.asPtr<UStringImpl*>() :  this; }
    261265    const UStringImpl* bufferOwnerString() const { return (bufferOwnership() == BufferSubstring) ? m_dataBuffer.asPtr<UStringImpl*>() :  this; }
Note: See TracChangeset for help on using the changeset viewer.