OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 14 matching lines...) Expand all Loading... |
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 * Boston, MA 02110-1301, USA. | 26 * Boston, MA 02110-1301, USA. |
27 */ | 27 */ |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/css/resolver/SharedStyleFinder.h" | 30 #include "core/css/resolver/SharedStyleFinder.h" |
31 | 31 |
32 #include "HTMLNames.h" | 32 #include "HTMLNames.h" |
33 #include "XMLNames.h" | 33 #include "XMLNames.h" |
34 #include "core/css/resolver/StyleResolver.h" | 34 #include "core/css/resolver/StyleResolver.h" |
| 35 #include "core/css/resolver/StyleResolverStats.h" |
35 #include "core/dom/ContainerNode.h" | 36 #include "core/dom/ContainerNode.h" |
36 #include "core/dom/Document.h" | 37 #include "core/dom/Document.h" |
37 #include "core/dom/Element.h" | 38 #include "core/dom/Element.h" |
38 #include "core/dom/ElementTraversal.h" | 39 #include "core/dom/ElementTraversal.h" |
39 #include "core/dom/FullscreenElementStack.h" | 40 #include "core/dom/FullscreenElementStack.h" |
40 #include "core/dom/Node.h" | 41 #include "core/dom/Node.h" |
41 #include "core/dom/NodeRenderStyle.h" | 42 #include "core/dom/NodeRenderStyle.h" |
42 #include "core/dom/QualifiedName.h" | 43 #include "core/dom/QualifiedName.h" |
43 #include "core/dom/SpaceSplitString.h" | 44 #include "core/dom/SpaceSplitString.h" |
44 #include "core/dom/shadow/ElementShadow.h" | 45 #include "core/dom/shadow/ElementShadow.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 if (!parent->childrenSupportStyleSharing()) | 234 if (!parent->childrenSupportStyleSharing()) |
234 return false; | 235 return false; |
235 } | 236 } |
236 | 237 |
237 return true; | 238 return true; |
238 } | 239 } |
239 | 240 |
240 bool SharedStyleFinder::documentContainsValidCandidate() const | 241 bool SharedStyleFinder::documentContainsValidCandidate() const |
241 { | 242 { |
242 for (Element* element = document().documentElement(); element; element = Ele
mentTraversal::next(*element)) { | 243 for (Element* element = document().documentElement(); element; element = Ele
mentTraversal::next(*element)) { |
243 if (canShareStyleWithElement(*element)) | 244 if (element->supportsStyleSharing() && canShareStyleWithElement(*element
)) |
244 return true; | 245 return true; |
245 } | 246 } |
246 return false; | 247 return false; |
247 } | 248 } |
248 | 249 |
249 inline Element* SharedStyleFinder::findElementForStyleSharing() const | 250 inline Element* SharedStyleFinder::findElementForStyleSharing() const |
250 { | 251 { |
251 StyleSharingList& styleSharingList = m_styleResolver.styleSharingList(); | 252 StyleSharingList& styleSharingList = m_styleResolver.styleSharingList(); |
252 for (StyleSharingList::iterator it = styleSharingList.begin(); it != styleSh
aringList.end(); ++it) { | 253 for (StyleSharingList::iterator it = styleSharingList.begin(); it != styleSh
aringList.end(); ++it) { |
253 Element& candidate = **it; | 254 Element& candidate = **it; |
(...skipping 13 matching lines...) Expand all Loading... |
267 bool SharedStyleFinder::matchesRuleSet(RuleSet* ruleSet) | 268 bool SharedStyleFinder::matchesRuleSet(RuleSet* ruleSet) |
268 { | 269 { |
269 if (!ruleSet) | 270 if (!ruleSet) |
270 return false; | 271 return false; |
271 ElementRuleCollector collector(m_context, m_styleResolver.selectorFilter()); | 272 ElementRuleCollector collector(m_context, m_styleResolver.selectorFilter()); |
272 return collector.hasAnyMatchingRules(ruleSet); | 273 return collector.hasAnyMatchingRules(ruleSet); |
273 } | 274 } |
274 | 275 |
275 RenderStyle* SharedStyleFinder::findSharedStyle() | 276 RenderStyle* SharedStyleFinder::findSharedStyle() |
276 { | 277 { |
277 STYLE_STATS_ADD_SEARCH(); | 278 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleLookups); |
278 | 279 |
279 if (!element().supportsStyleSharing()) | 280 if (!element().supportsStyleSharing()) |
280 return 0; | 281 return 0; |
281 | 282 |
282 STYLE_STATS_ADD_ELEMENT_ELIGIBLE_FOR_SHARING(); | |
283 | |
284 // Cache whether context.element() is affected by any known class selectors. | 283 // Cache whether context.element() is affected by any known class selectors. |
285 m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedBy
Rules(element().classNames()); | 284 m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedBy
Rules(element().classNames()); |
286 | 285 |
287 Element* shareElement = findElementForStyleSharing(); | 286 Element* shareElement = findElementForStyleSharing(); |
288 | 287 |
289 #ifdef STYLE_STATS | 288 if (!shareElement) { |
290 // FIXME: these stats don't to into account whether or not sibling/attribute | 289 if (m_styleResolver.stats() && m_styleResolver.stats()->printMissedCandi
dateCount && documentContainsValidCandidate()) |
291 // rules prevent these nodes from actually sharing | 290 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleMissed); |
292 if (shareElement) | 291 return 0; |
293 STYLE_STATS_ADD_SEARCH_FOUND_SIBLING_FOR_SHARING(); | 292 } |
294 else if (documentContainsValidCandidate()) | |
295 STYLE_STATS_ADD_SEARCH_MISSED_SHARING(); | |
296 #endif | |
297 | 293 |
298 // If we have exhausted all our budget or our cousins. | 294 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleFound); |
299 if (!shareElement) | 295 |
| 296 if (matchesRuleSet(m_siblingRuleSet)) { |
| 297 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedBySibl
ingRules); |
300 return 0; | 298 return 0; |
| 299 } |
301 | 300 |
302 // Can't share if sibling or attribute rules apply. This is checked at the e
nd as it should rarely fail. | 301 if (matchesRuleSet(m_uncommonAttributeRuleSet)) { |
303 if (matchesRuleSet(m_siblingRuleSet) || matchesRuleSet(m_uncommonAttributeRu
leSet)) | 302 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByUnco
mmonAttributeRules); |
304 return 0; | 303 return 0; |
| 304 } |
| 305 |
305 // Tracking child index requires unique style for each node. This may get se
t by the sibling rule match above. | 306 // Tracking child index requires unique style for each node. This may get se
t by the sibling rule match above. |
306 if (!element().parentElement()->childrenSupportStyleSharing()) | 307 if (!element().parentElement()->childrenSupportStyleSharing()) { |
| 308 INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByPare
nt); |
307 return 0; | 309 return 0; |
308 STYLE_STATS_ADD_STYLE_SHARED(); | 310 } |
| 311 |
309 return shareElement->renderStyle(); | 312 return shareElement->renderStyle(); |
310 } | 313 } |
311 | 314 |
312 } | 315 } |
OLD | NEW |