Ignore:
Timestamp:
Dec 22, 2009, 2:05:17 PM (15 years ago)
Author:
[email protected]
Message:

Fix a couple of problems with UntypedPtrAndBitfield.

Reviewed by Sam Weinig.

Add a m_leaksPtr to reduce false positives from leaks in debug builds
(this isn't perfect because we'd like a solution for release builds,
but this is now at least as good as a PtrAndFlags would be).

Switch SmallStringsto use a regular string for the base, rather than
a static one. UntypedPtrAndBitfield assumes all strings are at least
8 byte aligned; this migt not be true of static strings. Shared buffers
are heap allocated, as are all UStringImpls other than static strings.
Static strings cannot end up being the owner string of substrings,
since the only static strings are length 0.

  • runtime/SmallStrings.cpp:

(JSC::SmallStringsStorage::SmallStringsStorage):

  • runtime/UStringImpl.h:

(JSC::UntypedPtrAndBitfield::UntypedPtrAndBitfield):
(JSC::UStringImpl::UStringImpl):

File:
1 edited

Legend:

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

    r52463 r52500  
    4242
    4343private:
    44     UChar m_characters[numCharactersToStore];
    45     UString::Rep m_base;
    4644    UString::Rep m_reps[numCharactersToStore];
    4745};
    4846
    4947SmallStringsStorage::SmallStringsStorage()
    50     : m_base(m_characters, numCharactersToStore, UStringImpl::ConstructStaticString)
    5148{
    52     m_base.checkConsistency();
    53 
    54     for (unsigned i = 0; i < numCharactersToStore; ++i)
    55         m_characters[i] = i;
    56 
    57     memset(&m_reps, 0, sizeof(m_reps));
    58     for (unsigned i = 0; i < numCharactersToStore; ++i)
    59         new (&m_reps[i]) UString::Rep(m_base.data() + i, 1, &m_base);
     49    UChar* characterBuffer = 0;
     50    RefPtr<UStringImpl> baseString = UStringImpl::createUninitialized(numCharactersToStore, characterBuffer);
     51    for (unsigned i = 0; i < numCharactersToStore; ++i) {
     52        characterBuffer[i] = i;
     53        new (&m_reps[i]) UString::Rep(&characterBuffer[i], 1, PassRefPtr<UStringImpl>(baseString));
     54    }
    6055}
    6156
Note: See TracChangeset for help on using the changeset viewer.