Ignore:
Timestamp:
Jan 14, 2010, 10:43:21 PM (15 years ago)
Author:
[email protected]
Message:

JavaScriptCore: Make naming & behaviour of UString[Impl] methods more consistent.
https://bugs.webkit.org/show_bug.cgi?id=33702

Reviewed by Sam Weinig.

UString::create() creates a copy of the UChar* passed, but UStringImpl::create() assumes
that it should assume ownership of the provided buffer (with UString::createNonCopying()
and UStringImpl::createCopying() providing the alternate behaviours). Unify on create()
taking a copy of the provided buffer. For non-copying cases, use the name 'adopt', and
make this method take a Vector<UChar>&. For cases where non-copying construction was being
used, other than from a Vector<UChar>, change the code to allocate the storage along with
the UStringImpl using UStringImpl::createUninitialized(). (The adopt() method also more
closely matches that of WebCore::StringImpl).

Also, UString::createUninitialized() and UStringImpl::createUninitialized() have incompatible
behaviours, in that the UString form sets the provided UChar* to a null or non-null value to
indicate success or failure, but UStringImpl uses the returned PassRefPtr<UStringImpl> to
indicate when allocation has failed (potentially leaving the output Char* uninitialized).
This is also incompatible with WebCore::StringImpl's behaviour, in that
StringImpl::createUninitialized() will CRASH() if unable to allocate. Some uses of
createUninitialized() in JSC are unsafe, since they do not test the result for null.
UStringImpl's indication is preferable, since we may want a successful call to set the result
buffer to 0 (specifically, StringImpl returns 0 for the buffer where createUninitialized()
returns the empty string, which seems reasonable to catch bugs early). UString's method
cannot support UStringImpl's behaviour directly, since it returns an object rather than a
pointer.

  • remove UString::createUninitialized(), replace with calls to UStringImpl::createUninitialized()
  • create a UStringImpl::tryCreateUninitialized() form UStringImpl::createUninitialized(), with current behaviour, make createUninitialized() crash on failure to allocate.
  • make cases in JSC that do not check the result call createUninitialized(), and cases that do check call tryCreateUninitialized().

Rename computedHash() to existingHash(), to bring this in line wih WebCore::StringImpl.

  • API/JSClassRef.cpp:

(OpaqueJSClassContextData::OpaqueJSClassContextData):

(JSC::arrayProtoFuncToString):

  • runtime/Identifier.cpp:

(JSC::CStringTranslator::translate):
(JSC::UCharBufferTranslator::translate):

  • runtime/JSString.cpp:

(JSC::JSString::resolveRope):

  • runtime/Lookup.cpp:

(JSC::HashTable::createTable):

  • runtime/Lookup.h:

(JSC::HashTable::entry):

  • runtime/StringBuilder.h:

(JSC::StringBuilder::release):

  • runtime/StringConstructor.cpp:

(JSC::stringFromCharCodeSlowCase):

  • runtime/StringPrototype.cpp:

(JSC::substituteBackreferencesSlow):
(JSC::stringProtoFuncToLowerCase):
(JSC::stringProtoFuncToUpperCase):
(JSC::stringProtoFuncFontsize):
(JSC::stringProtoFuncLink):

  • runtime/Structure.cpp:

(JSC::Structure::despecifyDictionaryFunction):
(JSC::Structure::get):
(JSC::Structure::despecifyFunction):
(JSC::Structure::put):
(JSC::Structure::remove):
(JSC::Structure::insertIntoPropertyMapHashTable):
(JSC::Structure::checkConsistency):

  • runtime/Structure.h:

(JSC::Structure::get):

  • runtime/StructureTransitionTable.h:

(JSC::StructureTransitionTableHash::hash):

  • runtime/UString.cpp:

(JSC::createRep):
(JSC::UString::UString):
(JSC::UString::spliceSubstringsWithSeparators):
(JSC::UString::replaceRange):
(JSC::UString::operator=):

  • runtime/UString.h:

(JSC::UString::adopt):
(JSC::IdentifierRepHash::hash):
(JSC::makeString):

  • runtime/UStringImpl.h:

(JSC::UStringImpl::adopt):
(JSC::UStringImpl::create):
(JSC::UStringImpl::createUninitialized):
(JSC::UStringImpl::tryCreateUninitialized):
(JSC::UStringImpl::existingHash):

WebCore: Rubber stamped by Sam Weinig.

Make naming & behaviour of UString[Impl] methods more consistent.
https://bugs.webkit.org/show_bug.cgi?id=33702

WebCore change reflecting UString method name change computedHash() -> existingHash().

  • platform/text/AtomicString.cpp:

(WebCore::AtomicString::add):
(WebCore::AtomicString::find):

File:
1 edited

Legend:

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

    r53221 r53320  
    3232#include <wtf/PossiblyNull.h>
    3333#include <wtf/StringHashFunctions.h>
     34#include <wtf/Vector.h>
    3435#include <wtf/unicode/Unicode.h>
    3536
     
    8485class UStringImpl : Noncopyable {
    8586public:
    86     static PassRefPtr<UStringImpl> create(UChar* buffer, int length)
    87     {
    88         return adoptRef(new UStringImpl(buffer, length, BufferOwned));
    89     }
    90 
    91     static PassRefPtr<UStringImpl> createCopying(const UChar* buffer, int length)
     87    template<size_t inlineCapacity>
     88    static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector)
     89    {
     90        if (unsigned length = vector.size())
     91            return adoptRef(new UStringImpl(vector.releaseBuffer(), length, BufferOwned));
     92        return &empty();
     93    }
     94
     95    static PassRefPtr<UStringImpl> create(const UChar* buffer, int length)
    9296    {
    9397        UChar* newBuffer;
     
    112116    static PassRefPtr<UStringImpl> createUninitialized(unsigned length, UChar*& output)
    113117    {
    114         ASSERT(length);
     118        if (!length) {
     119            output = 0;
     120            return &empty();
     121        }
     122
     123        if (length > ((std::numeric_limits<size_t>::max() - sizeof(UStringImpl)) / sizeof(UChar)))
     124            CRASH();
     125        UStringImpl* resultImpl = static_cast<UStringImpl*>(fastMalloc(sizeof(UChar) * length + sizeof(UStringImpl)));
     126        output = reinterpret_cast<UChar*>(resultImpl + 1);
     127        return adoptRef(new(resultImpl) UStringImpl(output, length, BufferInternal));
     128    }
     129
     130    static PassRefPtr<UStringImpl> tryCreateUninitialized(unsigned length, UChar*& output)
     131    {
     132        if (!length) {
     133            output = 0;
     134            return &empty();
     135        }
     136
    115137        if (length > ((std::numeric_limits<size_t>::max() - sizeof(UStringImpl)) / sizeof(UChar)))
    116138            return 0;
    117 
    118139        UStringImpl* resultImpl;
    119140        if (!tryFastMalloc(sizeof(UChar) * length + sizeof(UStringImpl)).getValue(resultImpl))
    120141            return 0;
    121 
    122142        output = reinterpret_cast<UChar*>(resultImpl + 1);
    123143        return adoptRef(new(resultImpl) UStringImpl(output, length, BufferInternal));
     
    139159    }
    140160    unsigned hash() const { if (!m_hash) m_hash = computeHash(data(), m_length); return m_hash; }
    141     unsigned computedHash() const { ASSERT(m_hash); return m_hash; } // fast path for Identifiers
     161    unsigned existingHash() const { ASSERT(m_hash); return m_hash; } // fast path for Identifiers
    142162    void setHash(unsigned hash) { ASSERT(hash == computeHash(data(), m_length)); m_hash = hash; } // fast path for Identifiers
    143163    bool isIdentifier() const { return m_isIdentifier; }
Note: See TracChangeset for help on using the changeset viewer.