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

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: Rebased Created 7 years, 1 month 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) 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/page/Settings.h" 47 #include "core/page/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
56 static HashMap<AtomicString, StyleSheetContents*>& textToSheetCache()
57 {
58 typedef HashMap<AtomicString, StyleSheetContents*> TextToSheetCache;
esprehn 2013/11/15 10:27:37 No need for the typedefs since they're inside func
tasak 2014/01/09 09:24:50 I tried "DEFINE_STATIC_LOCAL((HashMap<...>), ..)".
59 DEFINE_STATIC_LOCAL(TextToSheetCache, cache, ());
60 return cache;
61 }
62
63 static HashMap<StyleSheetContents*, AtomicString>& sheetToTextCache()
64 {
65 typedef HashMap<StyleSheetContents*, AtomicString> SheetToTextCache;
esprehn 2013/11/15 10:27:37 Ditto.
66 DEFINE_STATIC_LOCAL(SheetToTextCache, cache, ());
67 return cache;
68 }
69
55 StyleEngine::StyleEngine(Document& document) 70 StyleEngine::StyleEngine(Document& document)
56 : m_document(document) 71 : m_document(document)
57 , m_pendingStylesheets(0) 72 , m_pendingStylesheets(0)
58 , m_injectedStyleSheetCacheValid(false) 73 , m_injectedStyleSheetCacheValid(false)
59 , m_needsUpdateActiveStylesheetsOnStyleRecalc(false) 74 , m_needsUpdateActiveStylesheetsOnStyleRecalc(false)
60 , m_documentStyleSheetCollection(document) 75 , m_documentStyleSheetCollection(document)
61 , m_needsDocumentStyleSheetsUpdate(true) 76 , m_needsDocumentStyleSheetsUpdate(true)
62 , m_usesSiblingRules(false) 77 , m_usesSiblingRules(false)
63 , m_usesSiblingRulesOverride(false) 78 , m_usesSiblingRulesOverride(false)
64 , m_usesFirstLineRules(false) 79 , m_usesFirstLineRules(false)
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 for (TreeScopeSet::iterator it = begin; it != end; ++it) { 424 for (TreeScopeSet::iterator it = begin; it != end; ++it) {
410 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it )) { 425 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it )) {
411 styleResolver->setBuildScopedStyleTreeInDocumentOrder(!collection->s copingNodesForStyleScoped()); 426 styleResolver->setBuildScopedStyleTreeInDocumentOrder(!collection->s copingNodesForStyleScoped());
412 styleResolver->appendAuthorStyleSheets(0, collection->activeAuthorSt yleSheets()); 427 styleResolver->appendAuthorStyleSheets(0, collection->activeAuthorSt yleSheets());
413 } 428 }
414 } 429 }
415 styleResolver->finishAppendAuthorStyleSheets(); 430 styleResolver->finishAppendAuthorStyleSheets();
416 styleResolver->setBuildScopedStyleTreeInDocumentOrder(false); 431 styleResolver->setBuildScopedStyleTreeInDocumentOrder(false);
417 } 432 }
418 433
434 PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& tex t, TextPosition startPosition, bool createdByParser)
435 {
436 AtomicString textContent(text);
437
438 HashMap<AtomicString, StyleSheetContents*>::AddResult result = textToSheetCa che().add(textContent, 0);
439
440 e->document().styleEngine()->addPendingSheet();
441
442 RefPtr<CSSStyleSheet> styleSheet;
443 if (result.isNewEntry || !result.iterator->value) {
444 styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->do cument().inputEncoding());
445 styleSheet->contents()->parseStringAtPosition(text, startPosition, creat edByParser);
446
447 if (result.isNewEntry && styleSheet->contents()->maybeCacheable()) {
448 result.iterator->value = styleSheet->contents();
449 sheetToTextCache().add(styleSheet->contents(), textContent);
450 }
451 } else {
452 ASSERT(result.iterator->value->maybeCacheable());
453 styleSheet = CSSStyleSheet::createInline(result.iterator->value, e, star tPosition);
454 }
455
456 ASSERT(styleSheet);
457 styleSheet->setTitle(e->title());
458
459 return styleSheet;
419 } 460 }
461
462 void StyleEngine::removeSheet(StyleSheetContents* contents)
463 {
464 HashMap<StyleSheetContents*, AtomicString>::iterator it = sheetToTextCache() .find(contents);
465 if (it == sheetToTextCache().end())
466 return;
467
468 textToSheetCache().remove(it->value);
469 sheetToTextCache().remove(contents);
470 }
471
472 void StyleEngine::clearSheetCache()
473 {
474 textToSheetCache().clear();
475 sheetToTextCache().clear();
esprehn 2013/11/15 10:27:37 Should not be needed. This is bad too, you're clea
tasak 2014/01/09 09:24:50 I'm still using this method when compatibility mod
476 }
477
478 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698