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

Side by Side Diff: Source/core/dom/Attr.cpp

Issue 203313002: Measure how often Attr needs its associated Element (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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/Attr.h ('k') | Source/core/dom/Attr.idl » ('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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2012 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2012 Apple Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 10 matching lines...) Expand all
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 */ 22 */
23 #include "config.h" 23 #include "config.h"
24 #include "core/dom/Attr.h" 24 #include "core/dom/Attr.h"
25 25
26 #include "bindings/v8/ExceptionState.h" 26 #include "bindings/v8/ExceptionState.h"
27 #include "bindings/v8/ExceptionStatePlaceholder.h" 27 #include "bindings/v8/ExceptionStatePlaceholder.h"
28 #include "core/dom/Element.h" 28 #include "core/dom/Element.h"
29 #include "core/dom/Text.h" 29 #include "core/dom/Text.h"
30 #include "core/events/ScopedEventQueue.h" 30 #include "core/events/ScopedEventQueue.h"
31 #include "core/frame/UseCounter.h"
31 #include "wtf/text/AtomicString.h" 32 #include "wtf/text/AtomicString.h"
32 #include "wtf/text/StringBuilder.h" 33 #include "wtf/text/StringBuilder.h"
33 34
34 namespace WebCore { 35 namespace WebCore {
35 36
36 using namespace HTMLNames; 37 using namespace HTMLNames;
37 38
38 Attr::Attr(Element& element, const QualifiedName& name) 39 Attr::Attr(Element& element, const QualifiedName& name)
39 : ContainerNode(&element.document()) 40 : ContainerNode(&element.document())
40 , m_element(&element) 41 , m_element(&element)
41 , m_name(name) 42 , m_name(name)
42 , m_ignoreChildrenChanged(0) 43 , m_ignoreChildrenChanged(0)
43 { 44 {
44 ScriptWrappable::init(this); 45 ScriptWrappable::init(this);
46 m_standaloneValue = value();
45 } 47 }
46 48
47 Attr::Attr(Document& document, const QualifiedName& name, const AtomicString& st andaloneValue) 49 Attr::Attr(Document& document, const QualifiedName& name, const AtomicString& st andaloneValue)
48 : ContainerNode(&document) 50 : ContainerNode(&document)
49 , m_element(0) 51 , m_element(0)
50 , m_name(name) 52 , m_name(name)
51 , m_standaloneValue(standaloneValue) 53 , m_standaloneValue(standaloneValue)
52 , m_ignoreChildrenChanged(0) 54 , m_ignoreChildrenChanged(0)
53 { 55 {
54 ScriptWrappable::init(this); 56 ScriptWrappable::init(this);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 89 }
88 } 90 }
89 91
90 void Attr::setValue(const AtomicString& value) 92 void Attr::setValue(const AtomicString& value)
91 { 93 {
92 EventQueueScope scope; 94 EventQueueScope scope;
93 m_ignoreChildrenChanged++; 95 m_ignoreChildrenChanged++;
94 removeChildren(); 96 removeChildren();
95 if (m_element) 97 if (m_element)
96 elementAttribute().setValue(value); 98 elementAttribute().setValue(value);
97 else 99 m_standaloneValue = value;
98 m_standaloneValue = value;
99 createTextChild(); 100 createTextChild();
100 m_ignoreChildrenChanged--; 101 m_ignoreChildrenChanged--;
101 102
102 invalidateNodeListCachesInAncestors(&m_name, m_element); 103 invalidateNodeListCachesInAncestors(&m_name, m_element);
103 } 104 }
104 105
105 void Attr::setValue(const AtomicString& value, ExceptionState&) 106 void Attr::setValue(const AtomicString& value, ExceptionState&)
106 { 107 {
107 if (m_element) 108 if (m_element)
108 m_element->willModifyAttribute(qualifiedName(), this->value(), value); 109 m_element->willModifyAttribute(qualifiedName(), this->value(), value);
109 110
110 setValue(value); 111 setValue(value);
111 112
112 if (m_element) 113 if (m_element)
113 m_element->didModifyAttribute(qualifiedName(), value); 114 m_element->didModifyAttribute(qualifiedName(), value);
114 } 115 }
115 116
117 const AtomicString& Attr::valueForBindings() const
118 {
119 if (m_element && m_standaloneValue != value())
120 UseCounter::count(document(), UseCounter::AttrGetValueNeedsElement);
121 return value();
122 }
123
124 void Attr::setValueForBindings(const AtomicString& value)
125 {
126 if (m_element && value != this->value())
127 UseCounter::count(document(), UseCounter::AttrSetValueNeedsElement);
128 setValue(value, IGNORE_EXCEPTION);
129 }
130
116 void Attr::setNodeValue(const String& v) 131 void Attr::setNodeValue(const String& v)
117 { 132 {
118 // Attr uses AtomicString type for its value to save memory as there 133 // Attr uses AtomicString type for its value to save memory as there
119 // is duplication among Elements' attributes values. 134 // is duplication among Elements' attributes values.
120 setValue(AtomicString(v), IGNORE_EXCEPTION); 135 setValue(AtomicString(v), IGNORE_EXCEPTION);
121 } 136 }
122 137
123 PassRefPtr<Node> Attr::cloneNode(bool /*deep*/) 138 PassRefPtr<Node> Attr::cloneNode(bool /*deep*/)
124 { 139 {
125 RefPtr<Attr> clone = adoptRef(new Attr(document(), qualifiedName(), value()) ); 140 RefPtr<Attr> clone = adoptRef(new Attr(document(), qualifiedName(), value()) );
126 cloneChildNodes(clone.get()); 141 cloneChildNodes(clone.get());
127 return clone.release(); 142 return clone.release();
128 } 143 }
129 144
130 // DOM Section 1.1.1 145 // DOM Section 1.1.1
131 bool Attr::childTypeAllowed(NodeType type) const 146 bool Attr::childTypeAllowed(NodeType type) const
132 { 147 {
133 return TEXT_NODE == type; 148 return TEXT_NODE == type;
134 } 149 }
135 150
136 void Attr::childrenChanged(bool, Node*, Node*, int) 151 void Attr::childrenChanged(bool, Node*, Node*, int)
137 { 152 {
138 if (m_ignoreChildrenChanged > 0) 153 if (m_ignoreChildrenChanged > 0)
139 return; 154 return;
140 155
156 UseCounter::count(document(), UseCounter::AttrChildrenChanged);
157
141 invalidateNodeListCachesInAncestors(&qualifiedName(), m_element); 158 invalidateNodeListCachesInAncestors(&qualifiedName(), m_element);
142 159
143 StringBuilder valueBuilder; 160 StringBuilder valueBuilder;
144 for (Node *n = firstChild(); n; n = n->nextSibling()) { 161 for (Node *n = firstChild(); n; n = n->nextSibling()) {
145 if (n->isTextNode()) 162 if (n->isTextNode())
146 valueBuilder.append(toText(n)->data()); 163 valueBuilder.append(toText(n)->data());
147 } 164 }
148 165
149 AtomicString newValue = valueBuilder.toAtomicString(); 166 AtomicString newValue = valueBuilder.toAtomicString();
150 if (m_element) 167 if (m_element)
151 m_element->willModifyAttribute(qualifiedName(), value(), newValue); 168 m_element->willModifyAttribute(qualifiedName(), value(), newValue);
152 169
153 if (m_element) 170 if (m_element)
154 elementAttribute().setValue(newValue); 171 elementAttribute().setValue(newValue);
155 else 172 m_standaloneValue = newValue;
156 m_standaloneValue = newValue;
157 173
158 if (m_element) 174 if (m_element)
159 m_element->attributeChanged(qualifiedName(), newValue); 175 m_element->attributeChanged(qualifiedName(), newValue);
160 } 176 }
161 177
162 const AtomicString& Attr::value() const 178 const AtomicString& Attr::value() const
163 { 179 {
164 if (m_element) 180 if (m_element)
165 return m_element->getAttribute(qualifiedName()); 181 return m_element->getAttribute(qualifiedName());
166 return m_standaloneValue; 182 return m_standaloneValue;
167 } 183 }
168 184
169 Attribute& Attr::elementAttribute() 185 Attribute& Attr::elementAttribute()
170 { 186 {
171 ASSERT(m_element); 187 ASSERT(m_element);
172 ASSERT(m_element->elementData()); 188 ASSERT(m_element->elementData());
173 return *m_element->ensureUniqueElementData().getAttributeItem(qualifiedName( )); 189 return *m_element->ensureUniqueElementData().getAttributeItem(qualifiedName( ));
174 } 190 }
175 191
176 void Attr::detachFromElementWithValue(const AtomicString& value) 192 void Attr::detachFromElementWithValue(const AtomicString& value)
177 { 193 {
178 ASSERT(m_element); 194 ASSERT(m_element);
179 ASSERT(m_standaloneValue.isNull());
180 m_standaloneValue = value; 195 m_standaloneValue = value;
181 m_element = 0; 196 m_element = 0;
182 } 197 }
183 198
184 void Attr::attachToElement(Element* element) 199 void Attr::attachToElement(Element* element)
185 { 200 {
186 ASSERT(!m_element); 201 ASSERT(!m_element);
187 m_element = element; 202 m_element = element;
188 m_standaloneValue = nullAtom; 203 m_standaloneValue = value();
189 } 204 }
190 205
191 } 206 }
OLDNEW
« no previous file with comments | « Source/core/dom/Attr.h ('k') | Source/core/dom/Attr.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698