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

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: 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
Index: Source/core/css/RuleSet.cpp
diff --git a/Source/core/css/RuleSet.cpp b/Source/core/css/RuleSet.cpp
index d2444cf5bc3681920ea816a2708bc623165d771b..1970e0c0f2045dd922c8400a8b9b76ad2d26669e 100644
--- a/Source/core/css/RuleSet.cpp
+++ b/Source/core/css/RuleSet.cpp
@@ -125,17 +125,14 @@ namespace {
template<typename T>
class TerminatedArrayBuilder {
public:
- explicit TerminatedArrayBuilder(PassOwnPtr<T> array)
+ explicit TerminatedArrayBuilder(PassOwnPtr<TerminatedArray<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;
+ m_capacity = m_count = m_array->size();
}
void grow(size_t count)
@@ -145,26 +142,26 @@ public:
ASSERT(!m_count);
ASSERT(!m_capacity);
m_capacity = count;
- m_array = adoptPtr(static_cast<T*>(fastMalloc(m_capacity * sizeof(T))));
+ m_array = TerminatedArray<T>::create(m_capacity);
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);
+ m_array = m_array.leakPtr()->realloc(m_capacity);
+ m_array->at(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;
+ m_array->at(m_count++) = item;
}
- PassOwnPtr<T> release()
+ PassOwnPtr<TerminatedArray<T> > release()
{
RELEASE_ASSERT(m_count == m_capacity);
if (m_array)
- m_array.get()[m_count - 1].setLastInArray(true);
+ m_array->at(m_count - 1).setLastInArray(true);
assertValid();
return m_array.release();
}
@@ -175,14 +172,14 @@ private:
{
for (size_t i = 0; i < m_count; ++i) {
bool isLastInArray = (i + 1 == m_count);
- ASSERT(m_array.get()[i].isLastInArray() == isLastInArray);
+ ASSERT(m_array->at(i).isLastInArray() == isLastInArray);
}
}
#else
void assertValid() { }
#endif
- OwnPtr<T> m_array;
+ OwnPtr<TerminatedArray<T> > m_array;
size_t m_count;
size_t m_capacity;
};

Powered by Google App Engine
This is Rietveld 408576698