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

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

Issue 28553005: Avoid parsing css text if there are identical inline style blocks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Patch for landing Created 6 years, 11 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/StyleEngine.h ('k') | Source/core/html/HTMLLinkElement.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) 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "core/page/Page.h" 45 #include "core/page/Page.h"
46 #include "core/page/PageGroup.h" 46 #include "core/page/PageGroup.h"
47 #include "core/frame/Settings.h" 47 #include "core/frame/Settings.h"
48 #include "core/svg/SVGStyleElement.h" 48 #include "core/svg/SVGStyleElement.h"
49 #include "platform/URLPatternMatcher.h" 49 #include "platform/URLPatternMatcher.h"
50 50
51 namespace WebCore { 51 namespace WebCore {
52 52
53 using namespace HTMLNames; 53 using namespace HTMLNames;
54 54
55 static HashMap<AtomicString, StyleSheetContents*>& textToSheetCache()
56 {
57 typedef HashMap<AtomicString, StyleSheetContents*> TextToSheetCache;
58 DEFINE_STATIC_LOCAL(TextToSheetCache, cache, ());
59 return cache;
60 }
61
62 static HashMap<StyleSheetContents*, AtomicString>& sheetToTextCache()
63 {
64 typedef HashMap<StyleSheetContents*, AtomicString> SheetToTextCache;
65 DEFINE_STATIC_LOCAL(SheetToTextCache, cache, ());
66 return cache;
67 }
68
55 StyleEngine::StyleEngine(Document& document) 69 StyleEngine::StyleEngine(Document& document)
56 : m_document(document) 70 : m_document(document)
57 , m_isMaster(HTMLImport::isMaster(&document)) 71 , m_isMaster(HTMLImport::isMaster(&document))
58 , m_pendingStylesheets(0) 72 , m_pendingStylesheets(0)
59 , m_injectedStyleSheetCacheValid(false) 73 , m_injectedStyleSheetCacheValid(false)
60 , m_needsUpdateActiveStylesheetsOnStyleRecalc(false) 74 , m_needsUpdateActiveStylesheetsOnStyleRecalc(false)
61 , m_documentStyleSheetCollection(document) 75 , m_documentStyleSheetCollection(document)
62 , m_documentScopeDirty(true) 76 , m_documentScopeDirty(true)
63 , m_usesSiblingRules(false) 77 , m_usesSiblingRules(false)
64 , m_usesSiblingRulesOverride(false) 78 , m_usesSiblingRulesOverride(false)
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 m_dirtyTreeScopes.add(&scope); 581 m_dirtyTreeScopes.add(&scope);
568 } 582 }
569 583
570 void StyleEngine::markDocumentDirty() 584 void StyleEngine::markDocumentDirty()
571 { 585 {
572 m_documentScopeDirty = true; 586 m_documentScopeDirty = true;
573 if (!HTMLImport::isMaster(&m_document)) 587 if (!HTMLImport::isMaster(&m_document))
574 m_document.import()->master()->styleEngine()->markDocumentDirty(); 588 m_document.import()->master()->styleEngine()->markDocumentDirty();
575 } 589 }
576 590
591 PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& tex t, TextPosition startPosition, bool createdByParser)
592 {
593 RefPtr<CSSStyleSheet> styleSheet;
594
595 e->document().styleEngine()->addPendingSheet();
596
597 if (!e->document().inQuirksMode()) {
598 AtomicString textContent(text);
599
600 HashMap<AtomicString, StyleSheetContents*>::AddResult result = textToShe etCache().add(textContent, 0);
601 if (result.isNewEntry || !result.iterator->value) {
602 styleSheet = StyleEngine::parseSheet(e, text, startPosition, created ByParser);
603 if (result.isNewEntry && styleSheet->contents()->maybeCacheable()) {
604 result.iterator->value = styleSheet->contents();
605 sheetToTextCache().add(styleSheet->contents(), textContent);
606 }
607 } else {
608 ASSERT(result.iterator->value->maybeCacheable());
609 styleSheet = CSSStyleSheet::createInline(result.iterator->value, e, startPosition);
610 }
611 } else {
612 // FIXME: currently we don't cache StyleSheetContents inQuirksMode.
613 styleSheet = StyleEngine::parseSheet(e, text, startPosition, createdByPa rser);
614 }
615
616 ASSERT(styleSheet);
617 styleSheet->setTitle(e->title());
618 return styleSheet;
577 } 619 }
620
621 PassRefPtr<CSSStyleSheet> StyleEngine::parseSheet(Element* e, const String& text , TextPosition startPosition, bool createdByParser)
622 {
623 RefPtr<CSSStyleSheet> styleSheet;
624 styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->docume nt().inputEncoding());
625 styleSheet->contents()->parseStringAtPosition(text, startPosition, createdBy Parser);
626 return styleSheet;
627 }
628
629 void StyleEngine::removeSheet(StyleSheetContents* contents)
630 {
631 HashMap<StyleSheetContents*, AtomicString>::iterator it = sheetToTextCache() .find(contents);
632 if (it == sheetToTextCache().end())
633 return;
634
635 textToSheetCache().remove(it->value);
636 sheetToTextCache().remove(contents);
637 }
638
639 }
OLDNEW
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | Source/core/html/HTMLLinkElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698