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

Unified Diff: Source/core/css/StyleSheetContentsCache.h

Issue 28553005: Avoid parsing css text if there are identical inline style blocks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added StyleSheetContentsCache class 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/css/StyleSheetContentsCache.h
diff --git a/Source/core/css/resolver/MatchedPropertiesCache.h b/Source/core/css/StyleSheetContentsCache.h
similarity index 51%
copy from Source/core/css/resolver/MatchedPropertiesCache.h
copy to Source/core/css/StyleSheetContentsCache.h
index 2e5297d5acd3c4bf14d2ca3cf161c2e593370ba6..054e8a679c660db77bfb700f4dd698a789b6cc10 100644
--- a/Source/core/css/resolver/MatchedPropertiesCache.h
+++ b/Source/core/css/StyleSheetContentsCache.h
@@ -20,54 +20,56 @@
*
*/
-#ifndef MatchedPropertiesCache_h
-#define MatchedPropertiesCache_h
-
-#include "core/css/resolver/MatchResult.h"
+#ifndef StyleSheetContentsCache_h
+#define StyleSheetContentsCache_h
+#include "core/css/StyleSheetContents.h"
#include "platform/Timer.h"
#include "wtf/Forward.h"
#include "wtf/HashMap.h"
#include "wtf/Noncopyable.h"
+#include "wtf/RefPtr.h"
+#include "wtf/text/AtomicString.h"
namespace WebCore {
-class RenderStyle;
-class StyleResolverState;
+class StyleSheetContents;
+
+class CachedStyleSheetContents {
dglazkov 2013/10/21 18:24:10 StyleSheetContentsCacheItem?
tasak 2013/10/25 05:23:13 Done.
+public:
+ static PassOwnPtr<CachedStyleSheetContents> create(StyleSheetContents*);
-struct CachedMatchedProperties {
- Vector<MatchedProperties> matchedProperties;
- MatchRanges ranges;
- RefPtr<RenderStyle> renderStyle;
- RefPtr<RenderStyle> parentRenderStyle;
+ unsigned addref() { return ++m_refCount; }
+ unsigned deref() { return --m_refCount; }
+ bool hasOneRef() { return m_refCount == 1; }
dglazkov 2013/10/21 18:24:10 Whoa! Why did you reinvent RefPtr here? :)
tasak 2013/10/25 05:23:13 I see. I re-implemented RefPtr... I made StyleShee
+ StyleSheetContents* contents() { return m_contents.get(); }
- void set(const RenderStyle*, const RenderStyle* parentStyle, const MatchResult&);
- void clear();
+private:
+ CachedStyleSheetContents(PassRefPtr<StyleSheetContents> contents) : m_refCount(0), m_contents(contents) { }
+
+ unsigned m_refCount;
+ RefPtr<StyleSheetContents> m_contents;
};
-class MatchedPropertiesCache {
- WTF_MAKE_NONCOPYABLE(MatchedPropertiesCache);
+class StyleSheetContentsCache {
+ WTF_MAKE_NONCOPYABLE(StyleSheetContentsCache);
public:
- MatchedPropertiesCache();
-
- const CachedMatchedProperties* find(unsigned hash, const StyleResolverState&, const MatchResult&);
- void add(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&);
+ StyleSheetContentsCache();
+ StyleSheetContents* find(const AtomicString& sheetText);
+ void add(const AtomicString& sheetText, StyleSheetContents*);
+ void remove(const AtomicString& sheetText);
void clear();
- static bool isCacheable(const Element*, const RenderStyle*, const RenderStyle* parentStyle);
-
private:
- // Every N additions to the matched declaration cache trigger a sweep where entries holding
- // the last reference to a style declaration are garbage collected.
- void sweep(Timer<MatchedPropertiesCache>*);
+ void sweep(Timer<StyleSheetContentsCache>*);
unsigned m_additionsSinceLastSweep;
- typedef HashMap<unsigned, OwnPtr<CachedMatchedProperties> > Cache;
+ typedef HashMap<AtomicString, OwnPtr<CachedStyleSheetContents> > Cache;
Cache m_cache;
- Timer<MatchedPropertiesCache> m_sweepTimer;
+ Timer<StyleSheetContentsCache> m_sweepTimer;
};
}

Powered by Google App Engine
This is Rietveld 408576698