Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: Source/core/dom/QualifiedName.h

Issue 311803003: [oilpan]: Avoid refcounting QualifiedName's nullQName when tracing. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review feedback Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/QualifiedName.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 16 matching lines...) Expand all
27 #include "wtf/text/AtomicString.h" 27 #include "wtf/text/AtomicString.h"
28 28
29 namespace WebCore { 29 namespace WebCore {
30 30
31 struct QualifiedNameComponents { 31 struct QualifiedNameComponents {
32 StringImpl* m_prefix; 32 StringImpl* m_prefix;
33 StringImpl* m_localName; 33 StringImpl* m_localName;
34 StringImpl* m_namespace; 34 StringImpl* m_namespace;
35 }; 35 };
36 36
37 // This struct is used pass data between QualifiedName and the QNameTranslator.
haraken 2014/06/12 10:57:15 is used to pass
wibling-chromium 2014/06/12 11:02:05 Done.
38 // For hashing and equality only the QualifiedNameComponents fields are used.
39 struct QualifiedNameData {
40 QualifiedNameComponents m_components;
41 bool m_isStatic;
42 };
43
37 class QualifiedName { 44 class QualifiedName {
38 WTF_MAKE_FAST_ALLOCATED; 45 WTF_MAKE_FAST_ALLOCATED;
39 public: 46 public:
40 class QualifiedNameImpl : public RefCounted<QualifiedNameImpl> { 47 class QualifiedNameImpl : public RefCounted<QualifiedNameImpl> {
41 public: 48 public:
42 static PassRefPtr<QualifiedNameImpl> create(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI) 49 static PassRefPtr<QualifiedNameImpl> create(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI, bool isStatic)
43 { 50 {
44 return adoptRef(new QualifiedNameImpl(prefix, localName, namespaceUR I)); 51 return adoptRef(new QualifiedNameImpl(prefix, localName, namespaceUR I, isStatic));
45 } 52 }
46 53
47 ~QualifiedNameImpl(); 54 ~QualifiedNameImpl();
48 55
49 unsigned computeHash() const; 56 unsigned computeHash() const;
50 57
51 mutable unsigned m_existingHash; 58 bool hasOneRef() const
59 {
60 return m_isStatic || RefCounted<QualifiedNameImpl>::hasOneRef();
61 }
62
63 void ref()
64 {
65 if (m_isStatic)
66 return;
67 RefCounted<QualifiedNameImpl>::ref();
68 }
69
70 void deref()
71 {
72 if (m_isStatic)
73 return;
74 RefCounted<QualifiedNameImpl>::deref();
75 }
76
52 const AtomicString m_prefix; 77 const AtomicString m_prefix;
53 const AtomicString m_localName; 78 const AtomicString m_localName;
54 const AtomicString m_namespace; 79 const AtomicString m_namespace;
55 mutable AtomicString m_localNameUpper; 80 mutable AtomicString m_localNameUpper;
81 // We rely on StringHasher's hashMemory clearing out the top 8 bits when
82 // doing hashing and use one of the bits for the m_isStatic value.
83 mutable unsigned m_existingHash : 24;
84 unsigned m_isStatic : 1;
56 85
57 private: 86 private:
58 QualifiedNameImpl(const AtomicString& prefix, const AtomicString& localN ame, const AtomicString& namespaceURI) 87 QualifiedNameImpl(const AtomicString& prefix, const AtomicString& localN ame, const AtomicString& namespaceURI, bool isStatic)
59 : m_existingHash(0) 88 : m_prefix(prefix)
60 , m_prefix(prefix)
61 , m_localName(localName) 89 , m_localName(localName)
62 , m_namespace(namespaceURI) 90 , m_namespace(namespaceURI)
91 , m_existingHash(0)
92 , m_isStatic(isStatic)
93
63 { 94 {
64 ASSERT(!namespaceURI.isEmpty() || namespaceURI.isNull()); 95 ASSERT(!namespaceURI.isEmpty() || namespaceURI.isNull());
65 } 96 }
66 }; 97 };
67 98
68 QualifiedName(const AtomicString& prefix, const AtomicString& localName, con st AtomicString& namespaceURI); 99 QualifiedName(const AtomicString& prefix, const AtomicString& localName, con st AtomicString& namespaceURI);
69 ~QualifiedName(); 100 ~QualifiedName();
70 #ifdef QNAME_DEFAULT_CONSTRUCTOR 101 #ifdef QNAME_DEFAULT_CONSTRUCTOR
71 QualifiedName() { } 102 QualifiedName() { }
72 #endif 103 #endif
(...skipping 22 matching lines...) Expand all
95 // Uppercased localName, cached for efficiency 126 // Uppercased localName, cached for efficiency
96 const AtomicString& localNameUpper() const; 127 const AtomicString& localNameUpper() const;
97 128
98 String toString() const; 129 String toString() const;
99 130
100 QualifiedNameImpl* impl() const { return m_impl.get(); } 131 QualifiedNameImpl* impl() const { return m_impl.get(); }
101 132
102 // Init routine for globals 133 // Init routine for globals
103 static void init(); 134 static void init();
104 135
136 static const QualifiedName& null();
137
138 // The below methods are only for creating static global QNames that need no ref counting.
139 static void createStatic(void* targetAddress, StringImpl* name);
140 static void createStatic(void* targetAddress, StringImpl* name, const Atomic String& nameNamespace);
141
105 private: 142 private:
143 // This constructor is used only to create global/static QNames that don't r equire any ref counting.
144 QualifiedName(const AtomicString& prefix, const AtomicString& localName, con st AtomicString& namespaceURI, bool isStatic);
145
106 RefPtr<QualifiedNameImpl> m_impl; 146 RefPtr<QualifiedNameImpl> m_impl;
107 }; 147 };
108 148
109 #ifndef WEBCORE_QUALIFIEDNAME_HIDE_GLOBALS 149 #ifndef WEBCORE_QUALIFIEDNAME_HIDE_GLOBALS
110 extern const QualifiedName anyName; 150 extern const QualifiedName anyName;
111 inline const QualifiedName& anyQName() { return anyName; } 151 inline const QualifiedName& anyQName() { return anyName; }
112 #endif 152 #endif
113 153
114 const QualifiedName& nullQName();
115
116 inline bool operator==(const AtomicString& a, const QualifiedName& q) { return a == q.localName(); } 154 inline bool operator==(const AtomicString& a, const QualifiedName& q) { return a == q.localName(); }
117 inline bool operator!=(const AtomicString& a, const QualifiedName& q) { return a != q.localName(); } 155 inline bool operator!=(const AtomicString& a, const QualifiedName& q) { return a != q.localName(); }
118 inline bool operator==(const QualifiedName& q, const AtomicString& a) { return a == q.localName(); } 156 inline bool operator==(const QualifiedName& q, const AtomicString& a) { return a == q.localName(); }
119 inline bool operator!=(const QualifiedName& q, const AtomicString& a) { return a != q.localName(); } 157 inline bool operator!=(const QualifiedName& q, const AtomicString& a) { return a != q.localName(); }
120 158
121 inline unsigned hashComponents(const QualifiedNameComponents& buf) 159 inline unsigned hashComponents(const QualifiedNameComponents& buf)
122 { 160 {
123 return StringHasher::hashMemory<sizeof(QualifiedNameComponents)>(&buf); 161 return StringHasher::hashMemory<sizeof(QualifiedNameComponents)>(&buf);
124 } 162 }
125 163
126 struct QualifiedNameHash { 164 struct QualifiedNameHash {
127 static unsigned hash(const QualifiedName& name) { return hash(name.impl()); } 165 static unsigned hash(const QualifiedName& name) { return hash(name.impl()); }
128 166
129 static unsigned hash(const QualifiedName::QualifiedNameImpl* name) 167 static unsigned hash(const QualifiedName::QualifiedNameImpl* name)
130 { 168 {
131 if (!name->m_existingHash) 169 if (!name->m_existingHash)
132 name->m_existingHash = name->computeHash(); 170 name->m_existingHash = name->computeHash();
133 return name->m_existingHash; 171 return name->m_existingHash;
134 } 172 }
135 173
136 static bool equal(const QualifiedName& a, const QualifiedName& b) { return a == b; } 174 static bool equal(const QualifiedName& a, const QualifiedName& b) { return a == b; }
137 static bool equal(const QualifiedName::QualifiedNameImpl* a, const Qualified Name::QualifiedNameImpl* b) { return a == b; } 175 static bool equal(const QualifiedName::QualifiedNameImpl* a, const Qualified Name::QualifiedNameImpl* b) { return a == b; }
138 176
139 static const bool safeToCompareToEmptyOrDeleted = false; 177 static const bool safeToCompareToEmptyOrDeleted = false;
140 }; 178 };
141 179
142 void createQualifiedName(void* targetAddress, StringImpl* name);
143 void createQualifiedName(void* targetAddress, StringImpl* name, const AtomicStri ng& nameNamespace);
144
145 } 180 }
146 181
147 namespace WTF { 182 namespace WTF {
148 183
149 template<typename T> struct DefaultHash; 184 template<typename T> struct DefaultHash;
150 185
151 template<> struct DefaultHash<WebCore::QualifiedName> { 186 template<> struct DefaultHash<WebCore::QualifiedName> {
152 typedef WebCore::QualifiedNameHash Hash; 187 typedef WebCore::QualifiedNameHash Hash;
153 }; 188 };
154 189
155 template<> struct HashTraits<WebCore::QualifiedName> : SimpleClassHashTraits <WebCore::QualifiedName> { 190 template<> struct HashTraits<WebCore::QualifiedName> : SimpleClassHashTraits <WebCore::QualifiedName> {
156 static const bool emptyValueIsZero = false; 191 static const bool emptyValueIsZero = false;
157 static WebCore::QualifiedName emptyValue() { return WebCore::nullQName() ; } 192 static WebCore::QualifiedName emptyValue() { return WebCore::QualifiedNa me::null(); }
158 }; 193 };
159 } 194 }
160 195
161 #endif 196 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/QualifiedName.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698