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

Side by Side Diff: third_party/WebKit/Source/core/dom/StyleEngine.cpp

Issue 2205843003: Use weak members to cache StyleSheetContents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Might be in cache without being used before garbage collection Created 4 years, 4 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
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 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 504 }
505 505
506 CSSStyleSheet* StyleEngine::createSheet(Element* e, const String& text, TextPosi tion startPosition, StyleEngineContext &context) 506 CSSStyleSheet* StyleEngine::createSheet(Element* e, const String& text, TextPosi tion startPosition, StyleEngineContext &context)
507 { 507 {
508 CSSStyleSheet* styleSheet = nullptr; 508 CSSStyleSheet* styleSheet = nullptr;
509 509
510 e->document().styleEngine().addPendingSheet(context); 510 e->document().styleEngine().addPendingSheet(context);
511 511
512 AtomicString textContent(text); 512 AtomicString textContent(text);
513 513
514 HeapHashMap<AtomicString, Member<StyleSheetContents>>::AddResult result = m_ textToSheetCache.add(textContent, nullptr); 514 auto result = m_textToSheetCache.add(textContent, nullptr);
515 if (result.isNewEntry || !result.storedValue->value) { 515 StyleSheetContents* contents = result.storedValue->value;
516 if (result.isNewEntry || !contents || !contents->isCacheableForStyleElement( )) {
517 result.storedValue->value = nullptr;
516 styleSheet = StyleEngine::parseSheet(e, text, startPosition); 518 styleSheet = StyleEngine::parseSheet(e, text, startPosition);
517 if (result.isNewEntry && styleSheet->contents()->isCacheableForStyleElem ent()) { 519 if (styleSheet->contents()->isCacheableForStyleElement()) {
518 result.storedValue->value = styleSheet->contents(); 520 result.storedValue->value = styleSheet->contents();
519 m_sheetToTextCache.add(styleSheet->contents(), textContent); 521 m_sheetToTextCache.add(styleSheet->contents(), textContent);
520 } 522 }
521 } else { 523 } else {
522 StyleSheetContents* contents = result.storedValue->value;
523 DCHECK(contents); 524 DCHECK(contents);
524 DCHECK(contents->isCacheableForStyleElement()); 525 DCHECK(contents->isCacheableForStyleElement());
525 DCHECK_EQ(contents->singleOwnerDocument(), e->document()); 526 DCHECK(contents->hasSingleOwnerDocument());
527 contents->setIsUsedFromTextCache();
526 styleSheet = CSSStyleSheet::createInline(contents, e, startPosition); 528 styleSheet = CSSStyleSheet::createInline(contents, e, startPosition);
527 } 529 }
528 530
529 DCHECK(styleSheet); 531 DCHECK(styleSheet);
530 styleSheet->setTitle(e->title()); 532 styleSheet->setTitle(e->title());
531 if (!e->isInShadowTree()) 533 if (!e->isInShadowTree())
532 setPreferredStylesheetSetNameIfNotSet(e->title()); 534 setPreferredStylesheetSetNameIfNotSet(e->title());
533 return styleSheet; 535 return styleSheet;
534 } 536 }
535 537
536 CSSStyleSheet* StyleEngine::parseSheet(Element* e, const String& text, TextPosit ion startPosition) 538 CSSStyleSheet* StyleEngine::parseSheet(Element* e, const String& text, TextPosit ion startPosition)
537 { 539 {
538 CSSStyleSheet* styleSheet = nullptr; 540 CSSStyleSheet* styleSheet = nullptr;
539 styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->docume nt().characterSet()); 541 styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->docume nt().characterSet());
540 styleSheet->contents()->parseStringAtPosition(text, startPosition); 542 styleSheet->contents()->parseStringAtPosition(text, startPosition);
541 return styleSheet; 543 return styleSheet;
542 } 544 }
543 545
544 void StyleEngine::removeSheet(StyleSheetContents* contents)
545 {
546 HeapHashMap<Member<StyleSheetContents>, AtomicString>::iterator it = m_sheet ToTextCache.find(contents);
547 if (it == m_sheetToTextCache.end())
548 return;
549
550 m_textToSheetCache.remove(it->value);
551 m_sheetToTextCache.remove(contents);
552 }
553
554 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const 546 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const
555 { 547 {
556 HeapHashSet<Member<const StyleSheetContents>> visitedSharedStyleSheetContent s; 548 HeapHashSet<Member<const StyleSheetContents>> visitedSharedStyleSheetContent s;
557 if (document().scopedStyleResolver()) 549 if (document().scopedStyleResolver())
558 document().scopedStyleResolver()->collectFeaturesTo(features, visitedSha redStyleSheetContents); 550 document().scopedStyleResolver()->collectFeaturesTo(features, visitedSha redStyleSheetContents);
559 for (TreeScope* treeScope : m_activeTreeScopes) { 551 for (TreeScope* treeScope : m_activeTreeScopes) {
560 // When creating StyleResolver, dirty treescopes might not be processed. 552 // When creating StyleResolver, dirty treescopes might not be processed.
561 // So some active treescopes might not have a scoped style resolver. 553 // So some active treescopes might not have a scoped style resolver.
562 // In this case, we should skip collectFeatures for the treescopes witho ut 554 // In this case, we should skip collectFeatures for the treescopes witho ut
563 // scoped style resolvers. When invoking updateActiveStyleSheets, 555 // scoped style resolvers. When invoking updateActiveStyleSheets,
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 821
830 DEFINE_TRACE_WRAPPERS(StyleEngine) 822 DEFINE_TRACE_WRAPPERS(StyleEngine)
831 { 823 {
832 for (auto sheet : m_injectedAuthorStyleSheets) { 824 for (auto sheet : m_injectedAuthorStyleSheets) {
833 visitor->traceWrappers(sheet); 825 visitor->traceWrappers(sheet);
834 } 826 }
835 visitor->traceWrappers(m_documentStyleSheetCollection); 827 visitor->traceWrappers(m_documentStyleSheetCollection);
836 } 828 }
837 829
838 } // namespace blink 830 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698