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.h

    r52463 r53320  
    104104        }
    105105
    106         static UString createNonCopying(UChar* c, int length);
     106        template<size_t inlineCapacity>
     107        static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector)
     108        {
     109            return Rep::adopt(vector);
     110        }
     111
    107112        static UString createFromUTF8(const char*);
    108         static UString createUninitialized(unsigned length, UChar*& output);
    109113
    110114        static UString from(int);
     
    274278
    275279    struct IdentifierRepHash : PtrHash<RefPtr<JSC::UString::Rep> > {
    276         static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->computedHash(); }
    277         static unsigned hash(JSC::UString::Rep* key) { return key->computedHash(); }
     280        static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->existingHash(); }
     281        static unsigned hash(JSC::UString::Rep* key) { return key->existingHash(); }
    278282    };
    279283
     
    358362        UChar* buffer;
    359363        unsigned length = adapter1.length() + adapter2.length();
    360         UString resultString = UString::createUninitialized(length, buffer);
    361         if (!buffer)
    362             return UString();
    363 
    364         UChar* result = buffer;
    365         adapter1.writeTo(result);
    366         result += adapter1.length();
    367         adapter2.writeTo(result);
    368 
    369         return resultString;
     364        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
     365        if (!resultImpl)
     366            return UString();
     367
     368        UChar* result = buffer;
     369        adapter1.writeTo(result);
     370        result += adapter1.length();
     371        adapter2.writeTo(result);
     372
     373        return resultImpl;
    370374    }
    371375
     
    379383        UChar* buffer;
    380384        unsigned length = adapter1.length() + adapter2.length() + adapter3.length();
    381         UString resultString = UString::createUninitialized(length, buffer);
    382         if (!buffer)
     385        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
     386        if (!resultImpl)
    383387            return UString();
    384388
     
    390394        adapter3.writeTo(result);
    391395
    392         return resultString;
     396        return resultImpl;
    393397    }
    394398
     
    403407        UChar* buffer;
    404408        unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length();
    405         UString resultString = UString::createUninitialized(length, buffer);
    406         if (!buffer)
     409        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
     410        if (!resultImpl)
    407411            return UString();
    408412
     
    416420        adapter4.writeTo(result);
    417421
    418         return resultString;
     422        return resultImpl;
    419423    }
    420424
     
    430434        UChar* buffer;
    431435        unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length();
    432         UString resultString = UString::createUninitialized(length, buffer);
    433         if (!buffer)
     436        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
     437        if (!resultImpl)
    434438            return UString();
    435439
     
    445449        adapter5.writeTo(result);
    446450
    447         return resultString;
     451        return resultImpl;
    448452    }
    449453
     
    460464        UChar* buffer;
    461465        unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length() + adapter6.length();
    462         UString resultString = UString::createUninitialized(length, buffer);
    463         if (!buffer)
     466        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
     467        if (!resultImpl)
    464468            return UString();
    465469
     
    477481        adapter6.writeTo(result);
    478482
    479         return resultString;
     483        return resultImpl;
    480484    }
    481485
     
    493497        UChar* buffer;
    494498        unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length() + adapter6.length() + adapter7.length();
    495         UString resultString = UString::createUninitialized(length, buffer);
    496         if (!buffer)
     499        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
     500        if (!resultImpl)
    497501            return UString();
    498502
     
    512516        adapter7.writeTo(result);
    513517
    514         return resultString;
     518        return resultImpl;
    515519    }
    516520
     
    529533        UChar* buffer;
    530534        unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length() + adapter6.length() + adapter7.length() + adapter8.length();
    531         UString resultString = UString::createUninitialized(length, buffer);
    532         if (!buffer)
     535        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
     536        if (!resultImpl)
    533537            return UString();
    534538
     
    550554        adapter8.writeTo(result);
    551555
    552         return resultString;
     556        return resultImpl;
    553557    }
    554558
Note: See TracChangeset for help on using the changeset viewer.