Changeset 57055 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Apr 3, 2010, 11:53:46 PM (15 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=37068
Change UString to use a 0 rep for null strings instead of a null object.

Reviewed by Oliver Hunt.

No performance impact.

(JSC::InternalFunction::InternalFunction):

  • runtime/JSString.h:

(JSC::RopeBuilder::JSString):

  • runtime/UString.cpp:

(JSC::initializeUString):

  • runtime/UString.h:

(JSC::UString::UString):
(JSC::UString::data):
(JSC::UString::size):
(JSC::UString::isNull):
(JSC::UString::isEmpty):
(JSC::UString::cost):

Location:
trunk/JavaScriptCore/runtime
Files:
4 edited

Legend:

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

    r51801 r57055  
    4141    : JSObject(structure)
    4242{
    43     putDirect(globalData->propertyNames->name, jsString(globalData, name.ustring()), DontDelete | ReadOnly | DontEnum);
     43    putDirect(globalData->propertyNames->name, jsString(globalData, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum);
    4444}
    4545
  • trunk/JavaScriptCore/runtime/JSString.h

    r57019 r57055  
    117117            , m_fiberCount(0)
    118118        {
     119            ASSERT(!m_value.isNull());
    119120            Heap::heap(this)->reportExtraMemoryCost(value.cost());
    120121        }
     
    127128            , m_fiberCount(0)
    128129        {
     130            ASSERT(!m_value.isNull());
    129131        }
    130132        JSString(JSGlobalData* globalData, PassRefPtr<UString::Rep> value, HasOtherOwnerType)
     
    134136            , m_fiberCount(0)
    135137        {
     138            ASSERT(!m_value.isNull());
    136139        }
    137140        JSString(JSGlobalData* globalData, PassRefPtr<Rope> rope)
     
    203206            , m_fiberCount(0)
    204207        {
     208            ASSERT(!m_value.isNull());
    205209            // nasty hack because we can't union non-POD types
    206210            m_other.m_finalizerCallback = finalizer;
  • trunk/JavaScriptCore/runtime/UString.cpp

    r56864 r57055  
    5959
    6060// The null string is immutable, except for refCount.
    61 UString::Rep* UString::s_nullRep;
    6261UString* UString::s_nullUString;
    6362
     
    6867    UStringImpl::empty();
    6968
    70     UString::s_nullRep = new UStringImpl(0, 0, UStringImpl::ConstructStaticString);
    7169    UString::s_nullUString = new UString;
    7270}
  • trunk/JavaScriptCore/runtime/UString.h

    r56864 r57055  
    4949   
    5050    public:
    51         UString();
     51        UString() {}
    5252        UString(const char*); // Constructor for null-terminated string.
    5353        UString(const char*, unsigned length);
     
    6363        UString(PlacementNewAdoptType)
    6464            : m_rep(PlacementNewAdopt)
    65         {
    66         }
    67 
    68         ~UString()
    6965        {
    7066        }
     
    9692        CString UTF8String(bool strict = false) const;
    9793
    98         const UChar* data() const { return m_rep->characters(); }
    99 
    100         bool isNull() const { return m_rep == s_nullRep; }
    101         bool isEmpty() const { return !m_rep->length(); }
     94        const UChar* data() const
     95        {
     96            if (!m_rep)
     97                return 0;
     98            return m_rep->characters();
     99        }
     100
     101        unsigned size() const
     102        {
     103            if (!m_rep)
     104                return 0;
     105            return m_rep->length();
     106        }
     107
     108        bool isNull() const { return !m_rep; }
     109        bool isEmpty() const { return !m_rep || !m_rep->length(); }
    102110
    103111        bool is8Bit() const;
    104 
    105         unsigned size() const { return m_rep->length(); }
    106112
    107113        UChar operator[](unsigned pos) const;
     
    132138            : m_rep(r)
    133139        {
    134             ASSERT(m_rep);
    135         }
    136 
    137         size_t cost() const { return m_rep->cost(); }
     140        }
     141
     142        size_t cost() const
     143        {
     144            if (!m_rep)
     145                return 0;
     146            return m_rep->cost();
     147        }
    138148
    139149    private:
    140150        RefPtr<Rep> m_rep;
    141151
    142         JS_EXPORTDATA static Rep* s_nullRep;
    143152        static UString* s_nullUString;
    144153
     
    194203
    195204    int compare(const UString&, const UString&);
    196 
    197     inline UString::UString()
    198         : m_rep(s_nullRep)
    199     {
    200     }
    201205
    202206    // Rule from ECMA 15.2 about what an array index is.
Note: See TracChangeset for help on using the changeset viewer.