Changeset 65286 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Aug 12, 2010, 6:05:10 PM (15 years ago)
Author:
[email protected]
Message:

Change UString constructors to match those in WTF::String.
This changes behaviour of UString((char*)0) to create null
strings, akin to UString() rather than UString::empty().
(This matches String). Remove unused constructors from
UString, and add null-terminated UTF-16 constructor, to
match String. Move String's constructor into the .cpp to
match UString.

Reviewed by Sam Weinig

(JSC::DebuggerCallFrame::calculatedFunctionName):

  • runtime/RegExpKey.h:

(JSC::RegExpKey::RegExpKey):

  • runtime/SmallStrings.cpp:

(JSC::SmallStrings::createSingleCharacterString):

  • runtime/UString.cpp:

(JSC::UString::UString):

  • runtime/UString.h:

(JSC::UString::UString):
(JSC::UString::swap):
(JSC::UString::adopt):
(JSC::UString::operator[]):

  • wtf/text/WTFString.h:

(WTF::String::String):
(WTF::String::adopt):
(WTF::String::operator[]):

Location:
trunk/JavaScriptCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r65268 r65286  
     12010-08-12  Gavin Barraclough  <[email protected]>
     2
     3        Reviewed by Sam Weinig
     4
     5        Change UString constructors to match those in WTF::String.
     6        This changes behaviour of UString((char*)0) to create null
     7        strings, akin to UString() rather than UString::empty().
     8        (This matches String).  Remove unused constructors from
     9        UString, and add null-terminated UTF-16 constructor, to
     10        match String.  Move String's constructor into the .cpp to
     11        match UString.
     12
     13        * JavaScriptCore.exp:
     14        * debugger/DebuggerCallFrame.cpp:
     15        (JSC::DebuggerCallFrame::calculatedFunctionName):
     16        * runtime/RegExpKey.h:
     17        (JSC::RegExpKey::RegExpKey):
     18        * runtime/SmallStrings.cpp:
     19        (JSC::SmallStrings::createSingleCharacterString):
     20        * runtime/UString.cpp:
     21        (JSC::UString::UString):
     22        * runtime/UString.h:
     23        (JSC::UString::UString):
     24        (JSC::UString::swap):
     25        (JSC::UString::adopt):
     26        (JSC::UString::operator[]):
     27        * wtf/text/WTFString.h:
     28        (WTF::String::String):
     29        (WTF::String::adopt):
     30        (WTF::String::operator[]):
     31
    1322010-08-12  David Levin  <[email protected]>
    233
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r65177 r65286  
    256256__ZN3JSC7UString6numberEj
    257257__ZN3JSC7UString6numberEl
    258 __ZN3JSC7UStringC1EPKc
    259 __ZN3JSC7UStringC1EPKtj
    260258__ZN3JSC8Debugger23recompileAllJSFunctionsEPNS_12JSGlobalDataE
    261259__ZN3JSC8Debugger6attachEPNS_14JSGlobalObjectE
     
    443441__ZN3WTF6String8fromUTF8EPKcm
    444442__ZN3WTF6String8truncateEj
     443__ZN3WTF6StringC1EPKc
     444__ZN3WTF6StringC1EPKcj
    445445__ZN3WTF6StringC1EPKt
     446__ZN3WTF6StringC1EPKtj
    446447__ZN3WTF6strtodEPKcPPc
    447448__ZN3WTF7CString11mutableDataEv
  • trunk/JavaScriptCore/debugger/DebuggerCallFrame.cpp

    r60392 r65286  
    5858    JSObject* function = m_callFrame->callee();
    5959    if (!function || !function->inherits(&JSFunction::info))
    60         return 0;
     60        return UString();
    6161
    6262    return asFunction(function)->calculatedDisplayName(m_callFrame);
  • trunk/JavaScriptCore/runtime/RegExpKey.h

    r65104 r65286  
    5959    }
    6060
     61    RegExpKey(int flags, const RefPtr<StringImpl>& pattern)
     62        : flagsValue(flags)
     63        , pattern(pattern)
     64    {
     65    }
     66
    6167    RegExpKey(const UString& flags, const UString& pattern)
    6268        : pattern(pattern.impl())
  • trunk/JavaScriptCore/runtime/SmallStrings.cpp

    r65104 r65286  
    130130        m_storage = adoptPtr(new SmallStringsStorage);
    131131    ASSERT(!m_singleCharacterStrings[character]);
    132     m_singleCharacterStrings[character] = new (globalData) JSString(globalData, m_storage->rep(character), JSString::HasOtherOwner);
     132    m_singleCharacterStrings[character] = new (globalData) JSString(globalData, PassRefPtr<StringImpl>(m_storage->rep(character)), JSString::HasOtherOwner);
    133133}
    134134
  • trunk/JavaScriptCore/runtime/UString.cpp

    r65266 r65286  
    5757COMPILE_ASSERT(sizeof(UString) == sizeof(void*), UString_should_stay_small);
    5858
    59 UString::UString(const char* c)
    60     : m_impl(StringImpl::create(c))
    61 {
    62 }
    63 
    64 UString::UString(const char* c, unsigned length)
    65     : m_impl(StringImpl::create(c, length))
    66 {
    67 }
    68 
    69 UString::UString(const UChar* c, unsigned length)
    70     : m_impl(StringImpl::create(c, length))
    71 {
    72 }
     59//    UString::UString(const UChar* characters, unsigned length)
     60//        : m_impl(characters ? StringImpl::create(characters, length) : 0)
     61//    {
     62//    }
     63UString::UString(const UChar* characters)
     64{
     65    if (!characters)
     66        return;
     67
     68    int length = 0;
     69    while (characters[length] != UChar(0))
     70        ++length;
     71
     72    m_impl = StringImpl::create(characters, length);
     73}
     74//    UString::UString(const char* characters)
     75//        : m_impl(characters ? StringImpl::create(characters) : 0)
     76//    {
     77//    }
     78//    UString::UString(const char* characters, unsigned length)
     79//        : m_impl(characters ? StringImpl::create(characters, length) : 0)
     80//    {
     81//    }
    7382
    7483UString UString::number(int i)
     
    209218
    210219    return asciiBuffer;
    211 }
    212 
    213 UChar UString::operator[](unsigned pos) const
    214 {
    215     if (pos >= length())
    216         return '\0';
    217     return characters()[pos];
    218220}
    219221
  • trunk/JavaScriptCore/runtime/UString.h

    r65268 r65286  
    4444class UString {
    4545public:
    46     UString() {}
    47     UString(const char*); // Constructor for null-terminated string.
    48     UString(const char*, unsigned length);
    49     UString(const UChar*, unsigned length);
    50     UString(const Vector<UChar>& buffer);
    51 
    52     UString(const UString& s)
    53         : m_impl(s.m_impl)
    54     {
    55     }
    56 
    57     // Special constructor for cases where we overwrite an object in place.
    58     UString(PlacementNewAdoptType)
    59         : m_impl(PlacementNewAdopt)
    60     {
    61     }
     46    // Construct a null string, distinguishable from an empty string.
     47    UString() { }
     48
     49    // Construct a string with UTF-16 data.
     50    UString(const UChar* characters, unsigned length)
     51        : m_impl(characters ? StringImpl::create(characters, length) : 0)
     52    {
     53    }
     54
     55    // Construct a string with UTF-16 data, from a null-terminated source.
     56    UString(const UChar*);
     57
     58    // Construct a string with latin1 data.
     59    UString(const char* characters)
     60        : m_impl(characters ? StringImpl::create(characters) : 0)
     61    {
     62    }
     63
     64    // Construct a string with latin1 data, from a null-terminated source.
     65    UString(const char* characters, unsigned length)
     66        : m_impl(characters ? StringImpl::create(characters, length) : 0)
     67    {
     68    }
     69
     70    // Construct a string referencing an existing StringImpl.
     71    UString(StringImpl* impl) : m_impl(impl) { }
     72    UString(PassRefPtr<StringImpl> impl) : m_impl(impl) { }
     73    UString(RefPtr<StringImpl> impl) : m_impl(impl) { }
     74
     75    void swap(UString& o) { m_impl.swap(o.m_impl); }
    6276
    6377    template<size_t inlineCapacity>
    64     static PassRefPtr<StringImpl> adopt(Vector<UChar, inlineCapacity>& vector)
    65     {
    66         return StringImpl::adopt(vector);
    67     }
     78    static UString adopt(Vector<UChar, inlineCapacity>& vector) { return StringImpl::adopt(vector); }
    6879
    6980    static UString number(int);
     
    101112    }
    102113
    103     UChar operator[](unsigned pos) const;
     114    UChar operator[](unsigned index) const
     115    {
     116        if (!m_impl || index >= m_impl->length())
     117            return 0;
     118        return m_impl->characters()[index];
     119    }
    104120
    105121    double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
     
    125141
    126142    StringImpl* impl() const { return m_impl.get(); }
    127 
    128     UString(PassRefPtr<StringImpl> r)
    129         : m_impl(r)
    130     {
    131     }
    132143
    133144    size_t cost() const
  • trunk/JavaScriptCore/wtf/text/WTFString.cpp

    r65021 r65286  
    3737using namespace Unicode;
    3838
     39// Construct a string with UTF-16 data.
     40String::String(const UChar* characters, unsigned length)
     41    : m_impl(characters ? StringImpl::create(characters, length) : 0)
     42{
     43}
     44
     45// Construct a string with UTF-16 data, from a null-terminated source.
    3946String::String(const UChar* str)
    4047{
     
    4754   
    4855    m_impl = StringImpl::create(str, len);
     56}
     57
     58// Construct a string with latin1 data.
     59String::String(const char* characters, unsigned length)
     60    : m_impl(characters ? StringImpl::create(characters, length) : 0)
     61{
     62}
     63
     64// Construct a string with latin1 data, from a null-terminated source.
     65String::String(const char* characters)
     66    : m_impl(characters ? StringImpl::create(characters) : 0)
     67{
    4968}
    5069
  • trunk/JavaScriptCore/wtf/text/WTFString.h

    r65264 r65286  
    7878class String {
    7979public:
    80     String() { } // gives null string, distinguishable from an empty string
    81     String(const UChar* str, unsigned len)
    82     {
    83         if (!str)
    84             return;
    85         m_impl = StringImpl::create(str, len);
    86     }
    87     String(const char* str)
    88     {
    89         if (!str)
    90             return;
    91         m_impl = StringImpl::create(str);
    92     }
    93     String(const char* str, unsigned length)
    94     {
    95         if (!str)
    96             return;
    97         m_impl = StringImpl::create(str, length);
    98     }
    99     String(const UChar*); // Specifically for null terminated UTF-16
    100     String(StringImpl* i) : m_impl(i) { }
    101     String(PassRefPtr<StringImpl> i) : m_impl(i) { }
    102     String(RefPtr<StringImpl> i) : m_impl(i) { }
     80    // Construct a null string, distinguishable from an empty string.
     81    String() { }
     82
     83    // Construct a string with UTF-16 data.
     84    String(const UChar* characters, unsigned length);
     85
     86    // Construct a string with UTF-16 data, from a null-terminated source.
     87    String(const UChar*);
     88
     89    // Construct a string with latin1 data.
     90    String(const char* characters, unsigned length);
     91
     92    // Construct a string with latin1 data, from a null-terminated source.
     93    String(const char* characters);
     94
     95    // Construct a string referencing an existing StringImpl.
     96    String(StringImpl* impl) : m_impl(impl) { }
     97    String(PassRefPtr<StringImpl> impl) : m_impl(impl) { }
     98    String(RefPtr<StringImpl> impl) : m_impl(impl) { }
    10399
    104100    void swap(String& o) { m_impl.swap(o.m_impl); }
     
    109105
    110106    static String adopt(StringBuffer& buffer) { return StringImpl::adopt(buffer); }
    111     static String adopt(Vector<UChar>& vector) { return StringImpl::adopt(vector); }
     107    template<size_t inlineCapacity>
     108    static String adopt(Vector<UChar, inlineCapacity>& vector) { return StringImpl::adopt(vector); }
     109
    112110
    113111    ALWAYS_INLINE unsigned length() const
     
    127125    const UChar* charactersWithNullTermination();
    128126   
    129     UChar operator[](unsigned i) const // if i >= length(), returns 0
     127    UChar operator[](unsigned index) const
    130128    {
    131         if (!m_impl || i >= m_impl->length())
     129        if (!m_impl || index >= m_impl->length())
    132130            return 0;
    133         return m_impl->characters()[i];
     131        return m_impl->characters()[index];
    134132    }
    135133    UChar32 characterStartingAt(unsigned) const; // Ditto.
Note: See TracChangeset for help on using the changeset viewer.