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

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

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: rebase 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/RuleSet.h ('k') | Source/core/css/RuleSetTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/RuleSet.cpp
diff --git a/Source/core/css/RuleSet.cpp b/Source/core/css/RuleSet.cpp
index d2444cf5bc3681920ea816a2708bc623165d771b..db044c3d999cd373de4b7127b44fb26723ece42c 100644
--- a/Source/core/css/RuleSet.cpp
+++ b/Source/core/css/RuleSet.cpp
@@ -43,6 +43,8 @@
#include "platform/TraceEvent.h"
#include "platform/weborigin/SecurityOrigin.h"
+#include "wtf/TerminatedArrayBuilder.h"
+
namespace WebCore {
using namespace HTMLNames;
@@ -119,76 +121,6 @@ static inline PropertyWhitelistType determinePropertyWhitelistType(const AddRule
return PropertyWhitelistNone;
}
-namespace {
-
-// FIXME: Should we move this class to WTF?
-template<typename T>
-class TerminatedArrayBuilder {
-public:
- explicit TerminatedArrayBuilder(PassOwnPtr<T> array)
- : m_array(array)
- , m_count(0)
- , m_capacity(0)
- {
- if (!m_array)
- return;
- for (T* item = m_array.get(); !item->isLastInArray(); ++item)
- ++m_count;
- ++m_count; // To count the last item itself.
- m_capacity = m_count;
- }
-
- void grow(size_t count)
- {
- ASSERT(count);
- if (!m_array) {
- ASSERT(!m_count);
- ASSERT(!m_capacity);
- m_capacity = count;
- m_array = adoptPtr(static_cast<T*>(fastMalloc(m_capacity * sizeof(T))));
- return;
- }
- m_capacity += count;
- m_array = adoptPtr(static_cast<T*>(fastRealloc(m_array.leakPtr(), m_capacity * sizeof(T))));
- m_array.get()[m_count - 1].setLastInArray(false);
- }
-
- void append(const T& item)
- {
- RELEASE_ASSERT(m_count < m_capacity);
- ASSERT(!item.isLastInArray());
- m_array.get()[m_count++] = item;
- }
-
- PassOwnPtr<T> release()
- {
- RELEASE_ASSERT(m_count == m_capacity);
- if (m_array)
- m_array.get()[m_count - 1].setLastInArray(true);
- assertValid();
- return m_array.release();
- }
-
-private:
-#ifndef NDEBUG
- void assertValid()
- {
- for (size_t i = 0; i < m_count; ++i) {
- bool isLastInArray = (i + 1 == m_count);
- ASSERT(m_array.get()[i].isLastInArray() == isLastInArray);
- }
- }
-#else
- void assertValid() { }
-#endif
-
- OwnPtr<T> m_array;
- size_t m_count;
- size_t m_capacity;
-};
-
-}
-
RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position, AddRuleFlags addRuleFlags)
: m_rule(rule)
, m_selectorIndex(selectorIndex)
« no previous file with comments | « Source/core/css/RuleSet.h ('k') | Source/core/css/RuleSetTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698