| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef OrderIterator_h | 31 #ifndef OrderIterator_h |
| 32 #define OrderIterator_h | 32 #define OrderIterator_h |
| 33 | 33 |
| 34 #include "wtf/HashMap.h" | |
| 35 #include "wtf/Noncopyable.h" | 34 #include "wtf/Noncopyable.h" |
| 36 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
| 37 | 36 |
| 38 namespace WebCore { | 37 namespace WebCore { |
| 39 | 38 |
| 40 class RenderBox; | 39 class RenderBox; |
| 41 | 40 |
| 42 // Normally, -1 and 0 are not valid in a HashSet, but these are relatively likel
y order: values. Instead, | |
| 43 // we make the two smallest int values invalid order: values (in the css parser
code we clamp them to | |
| 44 // int min + 2). | |
| 45 struct OrdererValueMapKeyHashTraits : WTF::GenericHashTraits<int> { | |
| 46 static const bool emptyValueIsZero = false; | |
| 47 static int emptyValue() { return std::numeric_limits<int>::min(); } | |
| 48 static void constructDeletedValue(int& slot) { slot = std::numeric_limits<in
t>::min() + 1; } | |
| 49 static bool isDeletedValue(int value) { return value == std::numeric_limits<
int>::min() + 1; } | |
| 50 }; | |
| 51 | |
| 52 class OrderIterator { | 41 class OrderIterator { |
| 53 WTF_MAKE_NONCOPYABLE(OrderIterator); | 42 WTF_MAKE_NONCOPYABLE(OrderIterator); |
| 54 public: | 43 public: |
| 55 friend class OrderIteratorPopulator; | 44 friend class OrderIteratorPopulator; |
| 56 | 45 |
| 57 OrderIterator(const RenderBox*); | 46 OrderIterator(const RenderBox*); |
| 58 | 47 |
| 59 RenderBox* currentChild() const { return m_currentChild; } | 48 RenderBox* currentChild() const { return m_currentChild; } |
| 60 RenderBox* first(); | 49 RenderBox* first(); |
| 61 RenderBox* next(); | 50 RenderBox* next(); |
| 62 void reset(); | 51 void reset(); |
| 63 | 52 |
| 64 void invalidate(); | |
| 65 | |
| 66 private: | 53 private: |
| 67 const RenderBox* m_containerBox; | 54 const RenderBox* m_containerBox; |
| 68 | 55 RenderBox* m_currentChild; |
| 69 // The inline capacity for a single item is used to cover the most | 56 // The inline capacity for a single item is used to cover the most |
| 70 // common case by far: if we only have the default 'order' value 0. | 57 // common case by far: if we only have the default 'order' value 0. |
| 71 typedef Vector<int, 1> OrderValues; | 58 typedef Vector<int, 1> OrderValues; |
| 72 OrderValues m_orderValues; | 59 OrderValues m_orderValues; |
| 73 | 60 Vector<int>::const_iterator m_orderValuesIterator; |
| 74 RenderBox* m_currentChild; | |
| 75 size_t m_currentOrderIndex; | |
| 76 size_t m_currentChildIndex; | |
| 77 | |
| 78 // This HashMap is empty if there is only one value. | |
| 79 typedef HashMap<int, Vector<RenderBox*>, DefaultHash<int>::Hash, OrdererValu
eMapKeyHashTraits > OrderedValuesMap; | |
| 80 OrderedValuesMap m_orderedValues; | |
| 81 }; | 61 }; |
| 82 | 62 |
| 83 class OrderIteratorPopulator { | 63 class OrderIteratorPopulator { |
| 84 public: | 64 public: |
| 85 OrderIteratorPopulator(OrderIterator& iterator) | 65 OrderIteratorPopulator(OrderIterator& iterator) |
| 86 : m_iterator(iterator) | 66 : m_iterator(iterator) |
| 67 , m_anyChildHasDefaultOrderValue(false) |
| 87 { | 68 { |
| 88 m_iterator.invalidate(); | 69 // Note that we don't release the memory here, we only invalidate the si
ze. |
| 70 // This avoids unneeded reallocation if the size ends up not changing. |
| 71 m_iterator.m_orderValues.shrink(0); |
| 89 } | 72 } |
| 90 | 73 |
| 91 ~OrderIteratorPopulator(); | 74 ~OrderIteratorPopulator(); |
| 92 | 75 |
| 93 void collectChild(RenderBox*); | 76 void collectChild(const RenderBox*); |
| 94 | 77 |
| 95 private: | 78 private: |
| 79 void removeDuplicatedOrderValues(); |
| 80 |
| 96 OrderIterator& m_iterator; | 81 OrderIterator& m_iterator; |
| 82 bool m_anyChildHasDefaultOrderValue; |
| 97 }; | 83 }; |
| 98 | 84 |
| 99 } // namespace WebCore | 85 } // namespace WebCore |
| 100 | 86 |
| 101 #endif // OrderIterator_h | 87 #endif // OrderIterator_h |
| OLD | NEW |