| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/heap/HeapCompact.h" | 5 #include "platform/heap/HeapCompact.h" |
| 6 | 6 |
| 7 #include "platform/heap/Handle.h" | 7 #include "platform/heap/Handle.h" |
| 8 #include "platform/heap/SparseHeapBitmap.h" | 8 #include "platform/heap/SparseHeapBitmap.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "wtf/Deque.h" | 10 #include "wtf/Deque.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 for (size_t i = 0; i < vector->size(); ++i) | 228 for (size_t i = 0; i < vector->size(); ++i) |
| 229 EXPECT_EQ(val, (*vector)[i]); | 229 EXPECT_EQ(val, (*vector)[i]); |
| 230 } | 230 } |
| 231 | 231 |
| 232 TEST(HeapCompactTest, CompactHashMap) { | 232 TEST(HeapCompactTest, CompactHashMap) { |
| 233 clearOutOldGarbage(); | 233 clearOutOldGarbage(); |
| 234 | 234 |
| 235 Persistent<IntMap> intMap = new IntMap(); | 235 Persistent<IntMap> intMap = new IntMap(); |
| 236 for (size_t i = 0; i < 100; ++i) { | 236 for (size_t i = 0; i < 100; ++i) { |
| 237 IntWrapper* val = IntWrapper::create(i); | 237 IntWrapper* val = IntWrapper::create(i); |
| 238 intMap->add(val, 100 - i); | 238 intMap->insert(val, 100 - i); |
| 239 } | 239 } |
| 240 | 240 |
| 241 EXPECT_EQ(100u, intMap->size()); | 241 EXPECT_EQ(100u, intMap->size()); |
| 242 for (auto k : *intMap) | 242 for (auto k : *intMap) |
| 243 EXPECT_EQ(k.key->value(), 100 - k.value); | 243 EXPECT_EQ(k.key->value(), 100 - k.value); |
| 244 | 244 |
| 245 performHeapCompaction(); | 245 performHeapCompaction(); |
| 246 | 246 |
| 247 for (auto k : *intMap) | 247 for (auto k : *intMap) |
| 248 EXPECT_EQ(k.key->value(), 100 - k.value); | 248 EXPECT_EQ(k.key->value(), 100 - k.value); |
| 249 } | 249 } |
| 250 | 250 |
| 251 TEST(HeapCompactTest, CompactVectorPartHashMap) { | 251 TEST(HeapCompactTest, CompactVectorPartHashMap) { |
| 252 clearOutOldGarbage(); | 252 clearOutOldGarbage(); |
| 253 | 253 |
| 254 using IntMapVector = HeapVector<IntMap>; | 254 using IntMapVector = HeapVector<IntMap>; |
| 255 | 255 |
| 256 Persistent<IntMapVector> intMapVector = new IntMapVector(); | 256 Persistent<IntMapVector> intMapVector = new IntMapVector(); |
| 257 for (size_t i = 0; i < 10; ++i) { | 257 for (size_t i = 0; i < 10; ++i) { |
| 258 IntMap map; | 258 IntMap map; |
| 259 for (size_t j = 0; j < 10; ++j) { | 259 for (size_t j = 0; j < 10; ++j) { |
| 260 IntWrapper* val = IntWrapper::create(j); | 260 IntWrapper* val = IntWrapper::create(j); |
| 261 map.add(val, 10 - j); | 261 map.insert(val, 10 - j); |
| 262 } | 262 } |
| 263 intMapVector->push_back(map); | 263 intMapVector->push_back(map); |
| 264 } | 264 } |
| 265 | 265 |
| 266 EXPECT_EQ(10u, intMapVector->size()); | 266 EXPECT_EQ(10u, intMapVector->size()); |
| 267 for (auto map : *intMapVector) { | 267 for (auto map : *intMapVector) { |
| 268 EXPECT_EQ(10u, map.size()); | 268 EXPECT_EQ(10u, map.size()); |
| 269 for (auto k : map) { | 269 for (auto k : map) { |
| 270 EXPECT_EQ(k.key->value(), 10 - k.value); | 270 EXPECT_EQ(k.key->value(), 10 - k.value); |
| 271 } | 271 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 286 clearOutOldGarbage(); | 286 clearOutOldGarbage(); |
| 287 | 287 |
| 288 using IntVectorMap = HeapHashMap<int, IntVector>; | 288 using IntVectorMap = HeapHashMap<int, IntVector>; |
| 289 | 289 |
| 290 Persistent<IntVectorMap> intVectorMap = new IntVectorMap(); | 290 Persistent<IntVectorMap> intVectorMap = new IntVectorMap(); |
| 291 for (size_t i = 0; i < 10; ++i) { | 291 for (size_t i = 0; i < 10; ++i) { |
| 292 IntVector vector; | 292 IntVector vector; |
| 293 for (size_t j = 0; j < 10; ++j) { | 293 for (size_t j = 0; j < 10; ++j) { |
| 294 vector.push_back(IntWrapper::create(j)); | 294 vector.push_back(IntWrapper::create(j)); |
| 295 } | 295 } |
| 296 intVectorMap->add(1 + i, vector); | 296 intVectorMap->insert(1 + i, vector); |
| 297 } | 297 } |
| 298 | 298 |
| 299 EXPECT_EQ(10u, intVectorMap->size()); | 299 EXPECT_EQ(10u, intVectorMap->size()); |
| 300 for (const IntVector& intVector : intVectorMap->values()) { | 300 for (const IntVector& intVector : intVectorMap->values()) { |
| 301 EXPECT_EQ(10u, intVector.size()); | 301 EXPECT_EQ(10u, intVector.size()); |
| 302 for (size_t i = 0; i < intVector.size(); ++i) { | 302 for (size_t i = 0; i < intVector.size(); ++i) { |
| 303 EXPECT_EQ(static_cast<int>(i), intVector[i]->value()); | 303 EXPECT_EQ(static_cast<int>(i), intVector[i]->value()); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 452 |
| 453 expected = 0; | 453 expected = 0; |
| 454 for (const Inner* v : *set) { | 454 for (const Inner* v : *set) { |
| 455 EXPECT_EQ(1u, v->size()); | 455 EXPECT_EQ(1u, v->size()); |
| 456 EXPECT_EQ(expected, (*v->begin())->value()); | 456 EXPECT_EQ(expected, (*v->begin())->value()); |
| 457 expected++; | 457 expected++; |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 | 460 |
| 461 } // namespace blink | 461 } // namespace blink |
| OLD | NEW |