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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.