Ignore:
Timestamp:
Jan 18, 2010, 9:51:40 PM (15 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=33731
Remove UntypedPtrAndBitfield from UStringImpl (akin to PtrAndFlags).

Patch by Gavin Barraclough <[email protected]> on 2010-01-18
Reviewed by Oliver Hunt.

This break the OS X Leaks tool. Instead, free up some more bits from the refCount.

  • runtime/UStringImpl.cpp:

(JSC::UStringImpl::sharedBuffer):
(JSC::UStringImpl::~UStringImpl):

  • runtime/UStringImpl.h:

(JSC::UStringImpl::cost):
(JSC::UStringImpl::checkConsistency):
(JSC::UStringImpl::UStringImpl):
(JSC::UStringImpl::bufferOwnerString):
(JSC::UStringImpl::):

  • wtf/StringHashFunctions.h:

(WTF::stringHash):

File:
1 edited

Legend:

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

    r53400 r53454  
    3636namespace JSC {
    3737 
    38 SharedUChar* UStringImpl::baseSharedBuffer()
    39 {
    40     ASSERT((bufferOwnership() == BufferShared)
    41         || ((bufferOwnership() == BufferOwned) && !m_dataBuffer.asPtr<void*>()));
    42 
    43     if (bufferOwnership() != BufferShared)
    44         m_dataBuffer = UntypedPtrAndBitfield(SharedUChar::create(new OwnFastMallocPtr<UChar>(m_data)).releaseRef(), BufferShared);
    45 
    46     return m_dataBuffer.asPtr<SharedUChar*>();
    47 }
    48 
    4938SharedUChar* UStringImpl::sharedBuffer()
    5039{
    51     if (m_length < s_minLengthToShare)
    52         return 0;
    53     ASSERT(!isStatic());
    54 
    55     UStringImpl* owner = bufferOwnerString();
    56     if (owner->bufferOwnership() == BufferInternal)
     40    if (m_length < s_minLengthToShare || isStatic())
    5741        return 0;
    5842
    59     return owner->baseSharedBuffer();
     43    switch (bufferOwnership()) {
     44    case BufferInternal:
     45        return 0;
     46    case BufferOwned:
     47        m_bufferShared = SharedUChar::create(new OwnFastMallocPtr<UChar>(m_data)).releaseRef();
     48        m_refCountAndFlags &= ~s_refCountMaskBufferOwnership;
     49        m_refCountAndFlags |= BufferShared;
     50        return m_bufferShared;
     51    case BufferSubstring:
     52        return m_bufferSubstring->sharedBuffer();
     53    case BufferShared:
     54        return m_bufferShared;
     55    }
     56
     57    ASSERT_NOT_REACHED();
     58    return 0;
    6059}
    6160
     
    6362{
    6463    ASSERT(!isStatic());
    65     checkConsistency();
    6664
    6765    if (isIdentifier())
    6866        Identifier::remove(this);
    6967
    70     if (bufferOwnership() != BufferInternal) {
    71         if (bufferOwnership() == BufferOwned)
    72             fastFree(m_data);
    73         else if (bufferOwnership() == BufferSubstring)
    74             m_dataBuffer.asPtr<UStringImpl*>()->deref();
    75         else {
    76             ASSERT(bufferOwnership() == BufferShared);
    77             m_dataBuffer.asPtr<SharedUChar*>()->deref();
    78         }
     68    switch (bufferOwnership()) {
     69    case BufferInternal:
     70        return;
     71    case BufferOwned:
     72        fastFree(m_data);
     73        return;
     74    case BufferSubstring:
     75        m_bufferSubstring->deref();
     76        return;
     77    case BufferShared:
     78        m_bufferSubstring->deref();
    7979    }
    8080}
    8181
    82 }
     82} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.