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

Side by Side Diff: Source/core/css/resolver/SharedStyleFinder.cpp

Issue 29633003: Avoid style sharing with mis-matched descendant selectors (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 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
OLDNEW
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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (parent->hasScopedHTMLStyleChild()) 263 if (parent->hasScopedHTMLStyleChild())
264 return false; 264 return false;
265 if (parent->inlineStyle()) 265 if (parent->inlineStyle())
266 return false; 266 return false;
267 if (parent->isSVGElement() && toSVGElement(parent)->animatedSMILStylePro perties()) 267 if (parent->isSVGElement() && toSVGElement(parent)->animatedSMILStylePro perties())
268 return false; 268 return false;
269 if (parent->hasID() && m_features.idsInRules.contains(parent->idForStyle Resolution().impl())) 269 if (parent->hasID() && m_features.idsInRules.contains(parent->idForStyle Resolution().impl()))
270 return false; 270 return false;
271 if (parentElementPreventsSharing(parent)) 271 if (parentElementPreventsSharing(parent))
272 return false; 272 return false;
273 if (!candidateMatchesDescendantRules(context, element))
esprehn 2013/10/21 19:19:08 The hotest part of style sharing is matching the r
274 return false;
273 } 275 }
274 276
275 return true; 277 return true;
276 } 278 }
277 279
278 #ifdef STYLE_STATS 280 #ifdef STYLE_STATS
279 Element* SharedStyleFinder::searchDocumentForSharedStyle(const ElementResolveCon text& context) const 281 Element* SharedStyleFinder::searchDocumentForSharedStyle(const ElementResolveCon text& context) const
280 { 282 {
281 for (Element* element = context.element()->document().documentElement(); ele ment; element = ElementTraversal::next(element)) { 283 for (Element* element = context.element()->document().documentElement(); ele ment; element = ElementTraversal::next(element)) {
282 if (canShareStyleWithElement(context, element)) 284 if (canShareStyleWithElement(context, element))
(...skipping 22 matching lines...) Expand all
305 } 307 }
306 308
307 bool SharedStyleFinder::matchesRuleSet(const ElementResolveContext& context, Rul eSet* ruleSet) 309 bool SharedStyleFinder::matchesRuleSet(const ElementResolveContext& context, Rul eSet* ruleSet)
308 { 310 {
309 if (!ruleSet) 311 if (!ruleSet)
310 return false; 312 return false;
311 ElementRuleCollector collector(context, m_styleResolver->selectorFilter()); 313 ElementRuleCollector collector(context, m_styleResolver->selectorFilter());
312 return collector.hasAnyMatchingRules(ruleSet); 314 return collector.hasAnyMatchingRules(ruleSet);
313 } 315 }
314 316
317 bool SharedStyleFinder::candidateMatchesDescendantRules(const ElementResolveCont ext& context, Element* candidate) const
318 {
319 if (!m_descendantRuleSet)
320 return false;
321
322 ElementResolveContext candidateContext(*candidate);
323
324 ElementRuleCollector collector(context, m_styleResolver->selectorFilter());
325 ElementRuleCollector candidateCollector(candidateContext, m_styleResolver->s electorFilter());
326 int firstRuleIndex = -1, lastRuleIndex = -1;
327 RuleRange ruleRange(firstRuleIndex, lastRuleIndex);
328 collector.collectMatchingRules(MatchRequest(m_descendantRuleSet), ruleRange, SelectorChecker::StaysWithinTreeScope);
329 candidateCollector.collectMatchingRules(MatchRequest(m_descendantRuleSet), r uleRange, SelectorChecker::StaysWithinTreeScope);
330 return collector.matchedResult().ranges == candidateCollector.matchedResult( ).ranges;
esprehn 2013/10/21 19:19:08 Matching rules like this is really expensive.
331 }
332
315 RenderStyle* SharedStyleFinder::locateSharedStyle(const ElementResolveContext& c ontext) 333 RenderStyle* SharedStyleFinder::locateSharedStyle(const ElementResolveContext& c ontext)
316 { 334 {
317 STYLE_STATS_ADD_SEARCH(); 335 STYLE_STATS_ADD_SEARCH();
318 336
319 if (!context.element()->supportsStyleSharing()) 337 if (!context.element()->supportsStyleSharing())
320 return 0; 338 return 0;
321 339
322 STYLE_STATS_ADD_ELEMENT_ELIGIBLE_FOR_SHARING(); 340 STYLE_STATS_ADD_ELEMENT_ELIGIBLE_FOR_SHARING();
323 341
324 // Cache whether context.element() is affected by any known class selectors. 342 // Cache whether context.element() is affected by any known class selectors.
(...skipping 23 matching lines...) Expand all
348 if (matchesRuleSet(context, m_siblingRuleSet) || matchesRuleSet(context, m_u ncommonAttributeRuleSet)) 366 if (matchesRuleSet(context, m_siblingRuleSet) || matchesRuleSet(context, m_u ncommonAttributeRuleSet))
349 return 0; 367 return 0;
350 // Tracking child index requires unique style for each node. This may get se t by the sibling rule match above. 368 // Tracking child index requires unique style for each node. This may get se t by the sibling rule match above.
351 if (parentElementPreventsSharing(context.element()->parentElement())) 369 if (parentElementPreventsSharing(context.element()->parentElement()))
352 return 0; 370 return 0;
353 STYLE_STATS_ADD_STYLE_SHARED(); 371 STYLE_STATS_ADD_STYLE_SHARED();
354 return shareElement->renderStyle(); 372 return shareElement->renderStyle();
355 } 373 }
356 374
357 } 375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698