| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r
ights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 118 } |
| 119 return PropertyWhitelistNone; | 119 return PropertyWhitelistNone; |
| 120 } | 120 } |
| 121 | 121 |
| 122 namespace { | 122 namespace { |
| 123 | 123 |
| 124 // FIXME: Should we move this class to WTF? | 124 // FIXME: Should we move this class to WTF? |
| 125 template<typename T> | 125 template<typename T> |
| 126 class TerminatedArrayBuilder { | 126 class TerminatedArrayBuilder { |
| 127 public: | 127 public: |
| 128 explicit TerminatedArrayBuilder(PassOwnPtr<T> array) | 128 explicit TerminatedArrayBuilder(PassOwnPtr<TerminatedArray<T> > array) |
| 129 : m_array(array) | 129 : m_array(array) |
| 130 , m_count(0) | 130 , m_count(0) |
| 131 , m_capacity(0) | 131 , m_capacity(0) |
| 132 { | 132 { |
| 133 if (!m_array) | 133 if (!m_array) |
| 134 return; | 134 return; |
| 135 for (T* item = m_array.get(); !item->isLastInArray(); ++item) | 135 m_capacity = m_count = m_array->size(); |
| 136 ++m_count; | |
| 137 ++m_count; // To count the last item itself. | |
| 138 m_capacity = m_count; | |
| 139 } | 136 } |
| 140 | 137 |
| 141 void grow(size_t count) | 138 void grow(size_t count) |
| 142 { | 139 { |
| 143 ASSERT(count); | 140 ASSERT(count); |
| 144 if (!m_array) { | 141 if (!m_array) { |
| 145 ASSERT(!m_count); | 142 ASSERT(!m_count); |
| 146 ASSERT(!m_capacity); | 143 ASSERT(!m_capacity); |
| 147 m_capacity = count; | 144 m_capacity = count; |
| 148 m_array = adoptPtr(static_cast<T*>(fastMalloc(m_capacity * sizeof(T)
))); | 145 m_array = TerminatedArray<T>::create(m_capacity); |
| 149 return; | 146 return; |
| 150 } | 147 } |
| 151 m_capacity += count; | 148 m_capacity += count; |
| 152 m_array = adoptPtr(static_cast<T*>(fastRealloc(m_array.leakPtr(), m_capa
city * sizeof(T)))); | 149 m_array = m_array.leakPtr()->realloc(m_capacity); |
| 153 m_array.get()[m_count - 1].setLastInArray(false); | 150 m_array->at(m_count - 1).setLastInArray(false); |
| 154 } | 151 } |
| 155 | 152 |
| 156 void append(const T& item) | 153 void append(const T& item) |
| 157 { | 154 { |
| 158 RELEASE_ASSERT(m_count < m_capacity); | 155 RELEASE_ASSERT(m_count < m_capacity); |
| 159 ASSERT(!item.isLastInArray()); | 156 ASSERT(!item.isLastInArray()); |
| 160 m_array.get()[m_count++] = item; | 157 m_array->at(m_count++) = item; |
| 161 } | 158 } |
| 162 | 159 |
| 163 PassOwnPtr<T> release() | 160 PassOwnPtr<TerminatedArray<T> > release() |
| 164 { | 161 { |
| 165 RELEASE_ASSERT(m_count == m_capacity); | 162 RELEASE_ASSERT(m_count == m_capacity); |
| 166 if (m_array) | 163 if (m_array) |
| 167 m_array.get()[m_count - 1].setLastInArray(true); | 164 m_array->at(m_count - 1).setLastInArray(true); |
| 168 assertValid(); | 165 assertValid(); |
| 169 return m_array.release(); | 166 return m_array.release(); |
| 170 } | 167 } |
| 171 | 168 |
| 172 private: | 169 private: |
| 173 #ifndef NDEBUG | 170 #ifndef NDEBUG |
| 174 void assertValid() | 171 void assertValid() |
| 175 { | 172 { |
| 176 for (size_t i = 0; i < m_count; ++i) { | 173 for (size_t i = 0; i < m_count; ++i) { |
| 177 bool isLastInArray = (i + 1 == m_count); | 174 bool isLastInArray = (i + 1 == m_count); |
| 178 ASSERT(m_array.get()[i].isLastInArray() == isLastInArray); | 175 ASSERT(m_array->at(i).isLastInArray() == isLastInArray); |
| 179 } | 176 } |
| 180 } | 177 } |
| 181 #else | 178 #else |
| 182 void assertValid() { } | 179 void assertValid() { } |
| 183 #endif | 180 #endif |
| 184 | 181 |
| 185 OwnPtr<T> m_array; | 182 OwnPtr<TerminatedArray<T> > m_array; |
| 186 size_t m_count; | 183 size_t m_count; |
| 187 size_t m_capacity; | 184 size_t m_capacity; |
| 188 }; | 185 }; |
| 189 | 186 |
| 190 } | 187 } |
| 191 | 188 |
| 192 RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position, A
ddRuleFlags addRuleFlags) | 189 RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position, A
ddRuleFlags addRuleFlags) |
| 193 : m_rule(rule) | 190 : m_rule(rule) |
| 194 , m_selectorIndex(selectorIndex) | 191 , m_selectorIndex(selectorIndex) |
| 195 , m_isLastInArray(false) | 192 , m_isLastInArray(false) |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 #ifndef NDEBUG | 430 #ifndef NDEBUG |
| 434 | 431 |
| 435 void RuleSet::show() | 432 void RuleSet::show() |
| 436 { | 433 { |
| 437 for (Vector<RuleData>::const_iterator it = m_allRules.begin(); it != m_allRu
les.end(); ++it) | 434 for (Vector<RuleData>::const_iterator it = m_allRules.begin(); it != m_allRu
les.end(); ++it) |
| 438 it->selector().show(); | 435 it->selector().show(); |
| 439 } | 436 } |
| 440 #endif | 437 #endif |
| 441 | 438 |
| 442 } // namespace WebCore | 439 } // namespace WebCore |
| OLD | NEW |