| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <cstring> | 6 #include <cstring> |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 table.InsertKey(entry, k); | 115 table.InsertKey(entry, k); |
| 116 EXPECT(!table.FindKeyOrDeletedOrUnused("f", &entry)); | 116 EXPECT(!table.FindKeyOrDeletedOrUnused("f", &entry)); |
| 117 k = String::New("f"); | 117 k = String::New("f"); |
| 118 table.InsertKey(entry, k); | 118 table.InsertKey(entry, k); |
| 119 EXPECT_EQ(5, table.NumOccupied()); | 119 EXPECT_EQ(5, table.NumOccupied()); |
| 120 } | 120 } |
| 121 table.Release(); | 121 table.Release(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 | 124 |
| 125 TEST_CASE(EnumIndexHashMap) { | |
| 126 typedef EnumIndexHashMap<TestTraits> Table; | |
| 127 Table table(HashTables::New<Table>(5)); | |
| 128 table.UpdateOrInsert(String::Handle(String::New("a")), | |
| 129 String::Handle(String::New("A"))); | |
| 130 EXPECT(table.ContainsKey("a")); | |
| 131 table.UpdateValue("a", String::Handle(String::New("AAA"))); | |
| 132 String& a_value = String::Handle(); | |
| 133 a_value ^= table.GetOrNull("a"); | |
| 134 EXPECT(a_value.Equals("AAA")); | |
| 135 Object& null_value = Object::Handle(table.GetOrNull("0")); | |
| 136 EXPECT(null_value.IsNull()); | |
| 137 | |
| 138 // Test on-demand allocation of a new key object using NewKey in traits. | |
| 139 String& b_value = String::Handle(); | |
| 140 b_value ^= | |
| 141 table.InsertNewOrGetValue("b", String::Handle(String::New("BBB"))); | |
| 142 EXPECT(b_value.Equals("BBB")); | |
| 143 { | |
| 144 // When the key is already present, there should be no allocation. | |
| 145 NoSafepointScope no_safepoint; | |
| 146 b_value ^= table.InsertNewOrGetValue("b", a_value); | |
| 147 EXPECT(b_value.Equals("BBB")); | |
| 148 } | |
| 149 table.Release(); | |
| 150 } | |
| 151 | |
| 152 | |
| 153 std::string ToStdString(const String& str) { | 125 std::string ToStdString(const String& str) { |
| 154 EXPECT(str.IsOneByteString()); | 126 EXPECT(str.IsOneByteString()); |
| 155 std::string result; | 127 std::string result; |
| 156 for (intptr_t i = 0; i < str.Length(); ++i) { | 128 for (intptr_t i = 0; i < str.Length(); ++i) { |
| 157 result += static_cast<char>(str.CharAt(i)); | 129 result += static_cast<char>(str.CharAt(i)); |
| 158 } | 130 } |
| 159 return result; | 131 return result; |
| 160 } | 132 } |
| 161 | 133 |
| 162 | 134 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 EXPECT_EQ(0, actual.NumOccupied()); | 255 EXPECT_EQ(0, actual.NumOccupied()); |
| 284 actual.Release(); | 256 actual.Release(); |
| 285 } | 257 } |
| 286 | 258 |
| 287 | 259 |
| 288 TEST_CASE(Sets) { | 260 TEST_CASE(Sets) { |
| 289 for (intptr_t initial_capacity = 0; | 261 for (intptr_t initial_capacity = 0; |
| 290 initial_capacity < 32; | 262 initial_capacity < 32; |
| 291 ++initial_capacity) { | 263 ++initial_capacity) { |
| 292 TestSet<UnorderedHashSet<TestTraits> >(initial_capacity, false); | 264 TestSet<UnorderedHashSet<TestTraits> >(initial_capacity, false); |
| 293 TestSet<EnumIndexHashSet<TestTraits> >(initial_capacity, true); | |
| 294 } | 265 } |
| 295 } | 266 } |
| 296 | 267 |
| 297 | 268 |
| 298 TEST_CASE(Maps) { | 269 TEST_CASE(Maps) { |
| 299 for (intptr_t initial_capacity = 0; | 270 for (intptr_t initial_capacity = 0; |
| 300 initial_capacity < 32; | 271 initial_capacity < 32; |
| 301 ++initial_capacity) { | 272 ++initial_capacity) { |
| 302 TestMap<UnorderedHashMap<TestTraits> >(initial_capacity, false); | 273 TestMap<UnorderedHashMap<TestTraits> >(initial_capacity, false); |
| 303 TestMap<EnumIndexHashMap<TestTraits> >(initial_capacity, true); | |
| 304 } | 274 } |
| 305 } | 275 } |
| 306 | 276 |
| 307 } // namespace dart | 277 } // namespace dart |
| OLD | NEW |