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/UString.cpp

    r52791 r53320  
    171171    size_t length = strlen(c);
    172172    UChar* d;
    173     PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, d);
     173    PassRefPtr<UStringImpl> result = UStringImpl::tryCreateUninitialized(length, d);
    174174    if (!result)
    175175        return &UString::Rep::null();
     
    189189
    190190    UChar* d;
    191     PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, d);
     191    PassRefPtr<UStringImpl> result = UStringImpl::tryCreateUninitialized(length, d);
    192192    if (!result)
    193193        return &UString::Rep::null();
     
    213213        m_rep = &Rep::empty();
    214214    else
    215         m_rep = Rep::createCopying(c, length);
    216 }
    217 
    218 UString UString::createNonCopying(UChar* c, int length)
    219 {
    220     if (length == 0)
    221         return UString(&Rep::empty());
    222     else
    223         return Rep::create(c, length);
     215        m_rep = Rep::create(c, length);
    224216}
    225217
     
    236228
    237229    return UString(buffer.data(), p - buffer.data());
    238 }
    239 
    240 UString UString::createUninitialized(unsigned length, UChar*& output)
    241 {
    242     if (!length) {
    243         output = &sharedEmptyChar;
    244         return UString(&Rep::empty());
    245     }
    246 
    247     if (PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, output))
    248         return result;
    249     output = 0;
    250     return UString();
    251230}
    252231
     
    391370
    392371    UChar* buffer;
    393     if (!UStringImpl::allocChars(totalLength).getValue(buffer))
     372    PassRefPtr<Rep> rep = Rep::tryCreateUninitialized(totalLength, buffer);
     373    if (!rep)
    394374        return null();
    395375
     
    407387    }
    408388
    409     return UString::Rep::create(buffer, totalLength);
     389    return rep;
    410390}
    411391
     
    420400
    421401    UChar* buffer;
    422     if (!UStringImpl::allocChars(totalLength).getValue(buffer))
     402    PassRefPtr<Rep> rep = Rep::tryCreateUninitialized(totalLength, buffer);
     403    if (!rep)
    423404        return null();
    424405
     
    428409    UStringImpl::copyChars(buffer + rangeStart + replacementLength, data() + rangeEnd, size() - rangeEnd);
    429410
    430     return UString::Rep::create(buffer, totalLength);
     411    return rep;
    431412}
    432413
     
    489470
    490471    int l = static_cast<int>(strlen(c));
    491     UChar* d;
    492     if (!UStringImpl::allocChars(l).getValue(d)) {
     472    UChar* d = 0;
     473    m_rep = Rep::tryCreateUninitialized(l, d);
     474    if (m_rep) {
     475        for (int i = 0; i < l; i++)
     476            d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
     477    } else
    493478        makeNull();
    494         return *this;
    495     }
    496     for (int i = 0; i < l; i++)
    497         d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
    498     m_rep = Rep::create(d, l);
    499479
    500480    return *this;
Note: See TracChangeset for help on using the changeset viewer.