diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/dom/QualifiedName.h')
-rw-r--r-- | chromium/third_party/WebKit/Source/core/dom/QualifiedName.h | 79 |
1 files changed, 55 insertions, 24 deletions
diff --git a/chromium/third_party/WebKit/Source/core/dom/QualifiedName.h b/chromium/third_party/WebKit/Source/core/dom/QualifiedName.h index b42f9e45cd2..46d4ad8cd3a 100644 --- a/chromium/third_party/WebKit/Source/core/dom/QualifiedName.h +++ b/chromium/third_party/WebKit/Source/core/dom/QualifiedName.h @@ -21,7 +21,6 @@ #ifndef QualifiedName_h #define QualifiedName_h -#include "wtf/Forward.h" #include "wtf/HashTableDeletedValueType.h" #include "wtf/HashTraits.h" #include "wtf/RefCounted.h" @@ -35,47 +34,80 @@ struct QualifiedNameComponents { StringImpl* m_namespace; }; +// This struct is used to pass data between QualifiedName and the QNameTranslator. +// For hashing and equality only the QualifiedNameComponents fields are used. +struct QualifiedNameData { + QualifiedNameComponents m_components; + bool m_isStatic; +}; + class QualifiedName { WTF_MAKE_FAST_ALLOCATED; public: class QualifiedNameImpl : public RefCounted<QualifiedNameImpl> { public: - static PassRefPtr<QualifiedNameImpl> create(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI) + static PassRefPtr<QualifiedNameImpl> create(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI, bool isStatic) { - return adoptRef(new QualifiedNameImpl(prefix, localName, namespaceURI)); + return adoptRef(new QualifiedNameImpl(prefix, localName, namespaceURI, isStatic)); } ~QualifiedNameImpl(); unsigned computeHash() const; - mutable unsigned m_existingHash; + bool hasOneRef() const + { + return m_isStatic || RefCounted<QualifiedNameImpl>::hasOneRef(); + } + + void ref() + { + if (m_isStatic) + return; + RefCounted<QualifiedNameImpl>::ref(); + } + + void deref() + { + if (m_isStatic) + return; + RefCounted<QualifiedNameImpl>::deref(); + } + const AtomicString m_prefix; const AtomicString m_localName; const AtomicString m_namespace; mutable AtomicString m_localNameUpper; + // We rely on StringHasher's hashMemory clearing out the top 8 bits when + // doing hashing and use one of the bits for the m_isStatic value. + mutable unsigned m_existingHash : 24; + unsigned m_isStatic : 1; private: - QualifiedNameImpl(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI) - : m_existingHash(0) - , m_prefix(prefix) + QualifiedNameImpl(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI, bool isStatic) + : m_prefix(prefix) , m_localName(localName) , m_namespace(namespaceURI) + , m_existingHash(0) + , m_isStatic(isStatic) + { ASSERT(!namespaceURI.isEmpty() || namespaceURI.isNull()); } }; QualifiedName(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI); - QualifiedName(WTF::HashTableDeletedValueType) : m_impl(hashTableDeletedValue()) { } - bool isHashTableDeletedValue() const { return m_impl == hashTableDeletedValue(); } ~QualifiedName(); #ifdef QNAME_DEFAULT_CONSTRUCTOR - QualifiedName() : m_impl(0) { } + QualifiedName() { } #endif - QualifiedName(const QualifiedName& other) : m_impl(other.m_impl) { ref(); } - const QualifiedName& operator=(const QualifiedName& other) { other.ref(); deref(); m_impl = other.m_impl; return *this; } + QualifiedName(const QualifiedName& other) : m_impl(other.m_impl) { } + const QualifiedName& operator=(const QualifiedName& other) { m_impl = other.m_impl; return *this; } + + // Hash table deleted values, which are only constructed and never copied or destroyed. + QualifiedName(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { } + bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); } bool operator==(const QualifiedName& other) const { return m_impl == other.m_impl; } bool operator!=(const QualifiedName& other) const { return !(*this == other); } @@ -96,18 +128,22 @@ public: String toString() const; - QualifiedNameImpl* impl() const { return m_impl; } + QualifiedNameImpl* impl() const { return m_impl.get(); } // Init routine for globals static void init(); -private: - void ref() const { m_impl->ref(); } - void deref(); + static const QualifiedName& null(); - static QualifiedNameImpl* hashTableDeletedValue() { return RefPtr<QualifiedNameImpl>::hashTableDeletedValue(); } + // The below methods are only for creating static global QNames that need no ref counting. + static void createStatic(void* targetAddress, StringImpl* name); + static void createStatic(void* targetAddress, StringImpl* name, const AtomicString& nameNamespace); - QualifiedNameImpl* m_impl; +private: + // This constructor is used only to create global/static QNames that don't require any ref counting. + QualifiedName(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI, bool isStatic); + + RefPtr<QualifiedNameImpl> m_impl; }; #ifndef WEBCORE_QUALIFIEDNAME_HIDE_GLOBALS @@ -115,8 +151,6 @@ extern const QualifiedName anyName; inline const QualifiedName& anyQName() { return anyName; } #endif -const QualifiedName& nullQName(); - inline bool operator==(const AtomicString& a, const QualifiedName& q) { return a == q.localName(); } inline bool operator!=(const AtomicString& a, const QualifiedName& q) { return a != q.localName(); } inline bool operator==(const QualifiedName& q, const AtomicString& a) { return a == q.localName(); } @@ -143,9 +177,6 @@ struct QualifiedNameHash { static const bool safeToCompareToEmptyOrDeleted = false; }; -void createQualifiedName(void* targetAddress, StringImpl* name); -void createQualifiedName(void* targetAddress, StringImpl* name, const AtomicString& nameNamespace); - } namespace WTF { @@ -158,7 +189,7 @@ namespace WTF { template<> struct HashTraits<WebCore::QualifiedName> : SimpleClassHashTraits<WebCore::QualifiedName> { static const bool emptyValueIsZero = false; - static WebCore::QualifiedName emptyValue() { return WebCore::nullQName(); } + static WebCore::QualifiedName emptyValue() { return WebCore::QualifiedName::null(); } }; } |