Ignore:
Timestamp:
Jan 9, 2009, 9:53:36 AM (16 years ago)
Author:
[email protected]
Message:

2009-01-09 David Levin <[email protected]>

Reviewed by Oliver Hunt.

https://bugs.webkit.org/show_bug.cgi?id=23175

Added a template to make the pointer and flags combination
in UString more readable and less error prone.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/UString.h

    r39554 r39747  
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    33 *  Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     4 *  Copyright (c) 2009, Google Inc. All rights reserved.
    45 *
    56 *  This library is free software; you can redistribute it and/or
     
    2930#include <wtf/FastMalloc.h>
    3031#include <wtf/PassRefPtr.h>
     32#include <wtf/PtrAndFlags.h>
    3133#include <wtf/RefPtr.h>
    3234#include <wtf/Vector.h>
     
    99101            static unsigned computeHash(const char* s) { return computeHash(s, strlen(s)); }
    100102
    101             IdentifierTable* identifierTable() const { return reinterpret_cast<IdentifierTable*>(m_identifierTable & ~static_cast<uintptr_t>(1)); }
    102             void setIdentifierTable(IdentifierTable* table) { ASSERT(!isStatic()); m_identifierTable = reinterpret_cast<intptr_t>(table); }
    103 
    104             bool isStatic() const { return m_identifierTable & 1; }
    105             void setStatic(bool v) { ASSERT(!identifierTable()); m_identifierTable = v; }
     103            IdentifierTable* identifierTable() const { return m_identifierTableAndFlags.get(); }
     104            void setIdentifierTable(IdentifierTable* table) { ASSERT(!isStatic()); m_identifierTableAndFlags.set(table); }
     105
     106            bool isStatic() const { return m_identifierTableAndFlags.isFlagSet(StaticFlag); }
     107            void setStatic(bool v) { ASSERT(!identifierTable()); if (v) m_identifierTableAndFlags.setFlag(StaticFlag); else m_identifierTableAndFlags.clearFlag(StaticFlag); }
    106108
    107109            Rep* ref() { ++rc; return this; }
     
    109111
    110112            void checkConsistency() const;
     113            enum UStringFlags {
     114                StaticFlag
     115            };
    111116
    112117            // unshared data
     
    115120            int rc; // For null and empty static strings, this field does not reflect a correct count, because ref/deref are not thread-safe. A special case in destroy() guarantees that these do not get deleted.
    116121            mutable unsigned _hash;
    117             intptr_t m_identifierTable; // A pointer to identifier table. The lowest bit is used to indicate whether the string is static (null or empty).
     122            PtrAndFlags<IdentifierTable, UStringFlags> m_identifierTableAndFlags;
    118123            UString::Rep* baseString;
    119124            size_t reportedCost;
     
    126131            int preCapacity;
    127132
    128             static Rep null;
    129             static Rep empty;
     133            static Rep& null() { return *nullBaseString; }
     134            static Rep& empty() { return *emptyBaseString; }
     135        private:
     136            friend void initializeUString();
     137            static Rep* nullBaseString;
     138            static Rep* emptyBaseString;
    130139        };
    131140
     
    205214        const UChar* data() const { return m_rep->data(); }
    206215
    207         bool isNull() const { return (m_rep == &Rep::null); }
     216        bool isNull() const { return (m_rep == &Rep::null()); }
    208217        bool isEmpty() const { return (!m_rep->len); }
    209218
     
    231240        UString substr(int pos = 0, int len = -1) const;
    232241
    233         static const UString& null();
     242        static const UString& null() { return *nullUString; }
    234243
    235244        Rep* rep() const { return m_rep.get(); }
     
    252261
    253262        RefPtr<Rep> m_rep;
    254 
     263        static UString* nullUString;
     264
     265        friend void initializeUString();
    255266        friend bool operator==(const UString&, const UString&);
    256267        friend PassRefPtr<Rep> concatenate(Rep*, Rep*); // returns 0 if out of memory
     
    306317
    307318    inline UString::UString()
    308         : m_rep(&Rep::null)
     319        : m_rep(&Rep::null())
    309320    {
    310321    }
     
    348359    };
    349360
     361    void initializeUString();
    350362} // namespace JSC
    351363
Note: See TracChangeset for help on using the changeset viewer.