OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2010, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2010, 2011, 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 bool containsAll(const SpaceSplitString& names) const { | 51 bool containsAll(const SpaceSplitString& names) const { |
52 return !names.m_data || (m_data && m_data->containsAll(*names.m_data)); | 52 return !names.m_data || (m_data && m_data->containsAll(*names.m_data)); |
53 } | 53 } |
54 void add(const AtomicString&); | 54 void add(const AtomicString&); |
55 bool remove(const AtomicString&); | 55 bool remove(const AtomicString&); |
56 | 56 |
57 size_t size() const { return m_data ? m_data->size() : 0; } | 57 size_t size() const { return m_data ? m_data->size() : 0; } |
58 bool isNull() const { return !m_data; } | 58 bool isNull() const { return !m_data; } |
59 const AtomicString& operator[](size_t i) const { | 59 const AtomicString& operator[](size_t i) const { |
60 ASSERT_WITH_SECURITY_IMPLICATION(i < size()); | |
61 return (*m_data)[i]; | 60 return (*m_data)[i]; |
62 } | 61 } |
63 | 62 |
64 private: | 63 private: |
65 class Data : public RefCounted<Data> { | 64 class Data : public RefCounted<Data> { |
66 public: | 65 public: |
67 static PassRefPtr<Data> create(const AtomicString&); | 66 static PassRefPtr<Data> create(const AtomicString&); |
68 static PassRefPtr<Data> createUnique(const Data&); | 67 static PassRefPtr<Data> createUnique(const Data&); |
69 | 68 |
70 ~Data(); | 69 ~Data(); |
71 | 70 |
72 bool contains(const AtomicString& string) { | 71 bool contains(const AtomicString& string) { |
73 size_t size = m_vector.size(); | 72 size_t size = m_vector.size(); |
74 for (size_t i = 0; i < size; ++i) { | 73 for (size_t i = 0; i < size; ++i) { |
75 if (m_vector[i] == string) | 74 if (m_vector[i] == string) |
76 return true; | 75 return true; |
77 } | 76 } |
78 return false; | 77 return false; |
79 } | 78 } |
80 | 79 |
81 bool containsAll(Data&); | 80 bool containsAll(Data&); |
82 | 81 |
83 void add(const AtomicString&); | 82 void add(const AtomicString&); |
84 void remove(unsigned index); | 83 void remove(unsigned index); |
85 | 84 |
86 bool isUnique() const { return m_keyString.isNull(); } | 85 bool isUnique() const { return m_keyString.isNull(); } |
87 size_t size() const { return m_vector.size(); } | 86 size_t size() const { return m_vector.size(); } |
88 const AtomicString& operator[](size_t i) { | 87 const AtomicString& operator[](size_t i) { |
89 ASSERT_WITH_SECURITY_IMPLICATION(i < size()); | |
90 return m_vector[i]; | 88 return m_vector[i]; |
91 } | 89 } |
92 | 90 |
93 private: | 91 private: |
94 explicit Data(const AtomicString&); | 92 explicit Data(const AtomicString&); |
95 explicit Data(const Data&); | 93 explicit Data(const Data&); |
96 | 94 |
97 void createVector(const String&); | 95 void createVector(const String&); |
98 template <typename CharacterType> | 96 template <typename CharacterType> |
99 inline void createVector(const CharacterType*, unsigned); | 97 inline void createVector(const CharacterType*, unsigned); |
100 | 98 |
101 AtomicString m_keyString; | 99 AtomicString m_keyString; |
102 Vector<AtomicString, 4> m_vector; | 100 Vector<AtomicString, 4> m_vector; |
103 }; | 101 }; |
104 typedef HashMap<AtomicString, Data*> DataMap; | 102 typedef HashMap<AtomicString, Data*> DataMap; |
105 | 103 |
106 static DataMap& sharedDataMap(); | 104 static DataMap& sharedDataMap(); |
107 | 105 |
108 void ensureUnique() { | 106 void ensureUnique() { |
109 if (m_data && !m_data->isUnique()) | 107 if (m_data && !m_data->isUnique()) |
110 m_data = Data::createUnique(*m_data); | 108 m_data = Data::createUnique(*m_data); |
111 } | 109 } |
112 | 110 |
113 RefPtr<Data> m_data; | 111 RefPtr<Data> m_data; |
114 }; | 112 }; |
115 | 113 |
116 } // namespace blink | 114 } // namespace blink |
117 | 115 |
118 #endif // SpaceSplitString_h | 116 #endif // SpaceSplitString_h |
OLD | NEW |