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

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

Issue 181403005: Introduce TerminatedArray<T> type to make data-structure used by RuleSet visible at the type level. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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
« no previous file with comments | « Source/core/css/ElementRuleCollector.cpp ('k') | Source/core/css/RuleSet.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/RuleSet.h
diff --git a/Source/core/css/RuleSet.h b/Source/core/css/RuleSet.h
index 8b259bd506f9aa49bbb8eb97a5f5b349cc5ac54d..b641aad5a84b5b7158b582a7d12498b99f91e326 100644
--- a/Source/core/css/RuleSet.h
+++ b/Source/core/css/RuleSet.h
@@ -114,6 +114,66 @@ struct SameSizeAsRuleData {
COMPILE_ASSERT(sizeof(RuleData) == sizeof(SameSizeAsRuleData), RuleData_should_stay_small);
+template<typename T>
+class TerminatedArray {
abarth-chromium 2014/03/04 19:03:35 Can you move this into it's own header in WTF?
Erik Corry 2014/03/05 11:43:52 I think this is rather too hacky to move to WTF.
Vyacheslav Egorov (Chromium) 2014/03/05 12:44:07 I decided to move both TerminatedArray and Termina
+ WTF_MAKE_FAST_ALLOCATED;
haraken 2014/03/05 01:47:06 Add WTF_MAKE_NONCOPYABLE(TerminatedArray).
Vyacheslav Egorov (Chromium) 2014/03/05 12:44:07 Done.
+public:
+ static PassOwnPtr<TerminatedArray> create(size_t capacity)
+ {
+ return adoptPtr(static_cast<TerminatedArray*>(fastMalloc(capacity * sizeof(T))));
Erik Corry 2014/03/05 11:43:52 Consider using zeroed malloc here, since normally
Vyacheslav Egorov (Chromium) 2014/03/05 12:44:07 I will all be filled with real objects, so zeroing
+ }
+
+ PassOwnPtr<TerminatedArray> realloc(size_t capacity)
haraken 2014/03/05 01:47:06 realloc => resize ?
Vyacheslav Egorov (Chromium) 2014/03/05 12:44:07 Done.
+ {
+ return adoptPtr(static_cast<TerminatedArray*>(fastRealloc(this, capacity * sizeof(T))));
+ }
+
+ T& at(size_t idx) { return reinterpret_cast<T*>(this)[idx]; }
abarth-chromium 2014/03/04 19:03:35 idx -> index
Vyacheslav Egorov (Chromium) 2014/03/05 12:44:07 Done.
+ const T& at(size_t idx) const { return reinterpret_cast<const T*>(this)[idx]; }
haraken 2014/03/05 01:47:06 Shall we add operator[] ?
Vyacheslav Egorov (Chromium) 2014/03/05 12:44:07 It will be useless because we pass these arrays by
+
+ template<typename U>
+ class iterator_base {
+ public:
+ iterator_base& operator++()
+ {
+ if (m_val->isLastInArray()) {
+ m_val = 0;
+ } else {
+ ++m_val;
+ }
+ return *this;
+ }
+
+ U& operator*() const { return *m_val; }
+
+ bool operator!=(const iterator_base& other) { return m_val != other.m_val; }
haraken 2014/03/05 01:47:06 Shall we add operator== ?
Vyacheslav Egorov (Chromium) 2014/03/05 12:44:07 Done.
+
+ private:
+ iterator_base(U* val) : m_val(val) { }
+
+ U* m_val;
+
+ friend class TerminatedArray;
+ };
+
+ typedef iterator_base<T> iterator;
+ typedef iterator_base<const T> const_iterator;
+
+ iterator begin() { return iterator(reinterpret_cast<T*>(this)); }
+ const_iterator begin() const { return const_iterator(reinterpret_cast<const T*>(this)); }
+
+ iterator end() { return iterator(0); }
+ const_iterator end() const { return const_iterator(0); }
+
+ size_t size() const
wibling-chromium 2014/03/05 09:28:32 Consider adding a comment describing how this data
Vyacheslav Egorov (Chromium) 2014/03/05 12:44:07 Done.
+ {
+ size_t count = 0;
+ for (const_iterator it = begin(); it != end(); ++it)
+ count++;
+ return count;
+ }
+};
+
class RuleSet {
WTF_MAKE_NONCOPYABLE(RuleSet); WTF_MAKE_FAST_ALLOCATED;
public:
@@ -125,10 +185,10 @@ public:
const RuleFeatureSet& features() const { return m_features; }
- const RuleData* idRules(const AtomicString& key) const { ASSERT(!m_pendingRules); return m_idRules.get(key); }
- const RuleData* classRules(const AtomicString& key) const { ASSERT(!m_pendingRules); return m_classRules.get(key); }
- const RuleData* tagRules(const AtomicString& key) const { ASSERT(!m_pendingRules); return m_tagRules.get(key); }
- const RuleData* shadowPseudoElementRules(const AtomicString& key) const { ASSERT(!m_pendingRules); return m_shadowPseudoElementRules.get(key); }
+ const TerminatedArray<RuleData>* idRules(const AtomicString& key) const { ASSERT(!m_pendingRules); return m_idRules.get(key); }
+ const TerminatedArray<RuleData>* classRules(const AtomicString& key) const { ASSERT(!m_pendingRules); return m_classRules.get(key); }
+ const TerminatedArray<RuleData>* tagRules(const AtomicString& key) const { ASSERT(!m_pendingRules); return m_tagRules.get(key); }
+ const TerminatedArray<RuleData>* shadowPseudoElementRules(const AtomicString& key) const { ASSERT(!m_pendingRules); return m_shadowPseudoElementRules.get(key); }
const Vector<RuleData>* linkPseudoClassRules() const { ASSERT(!m_pendingRules); return &m_linkPseudoClassRules; }
const Vector<RuleData>* cuePseudoRules() const { ASSERT(!m_pendingRules); return &m_cuePseudoRules; }
const Vector<RuleData>* focusPseudoClassRules() const { ASSERT(!m_pendingRules); return &m_focusPseudoClassRules; }
@@ -164,7 +224,7 @@ public:
private:
typedef HashMap<AtomicString, OwnPtr<LinkedStack<RuleData> > > PendingRuleMap;
- typedef HashMap<AtomicString, OwnPtr<RuleData> > CompactRuleMap;
+ typedef HashMap<AtomicString, OwnPtr<TerminatedArray<RuleData> > > CompactRuleMap;
RuleSet()
: m_ruleCount(0)
« no previous file with comments | « Source/core/css/ElementRuleCollector.cpp ('k') | Source/core/css/RuleSet.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698