OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 5329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5340 Persistent<DeepEagerly> persistent(obj); | 5340 Persistent<DeepEagerly> persistent(obj); |
5341 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 5341 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
5342 | 5342 |
5343 // Verify that the DeepEagerly chain isn't completely unravelled | 5343 // Verify that the DeepEagerly chain isn't completely unravelled |
5344 // by performing eager trace() calls, but the explicit mark | 5344 // by performing eager trace() calls, but the explicit mark |
5345 // stack is switched once some nesting limit is exceeded. | 5345 // stack is switched once some nesting limit is exceeded. |
5346 EXPECT_GT(DeepEagerly::sTraceLazy, 2); | 5346 EXPECT_GT(DeepEagerly::sTraceLazy, 2); |
5347 #endif | 5347 #endif |
5348 } | 5348 } |
5349 | 5349 |
| 5350 TEST(HeapTest, DequeExpand) |
| 5351 { |
| 5352 // Test expansion of a HeapDeque<>'s buffer. |
| 5353 |
| 5354 typedef HeapDeque<Member<IntWrapper>> IntDeque; |
| 5355 |
| 5356 Persistent<IntDeque> deque = new IntDeque(); |
| 5357 |
| 5358 // Append a sequence, bringing about repeated expansions of the |
| 5359 // deque's buffer. |
| 5360 int i = 0; |
| 5361 for (; i < 60; ++i) |
| 5362 deque->append(IntWrapper::create(i)); |
| 5363 |
| 5364 EXPECT_EQ(60u, deque->size()); |
| 5365 i = 0; |
| 5366 for (const auto& intWrapper : *deque) { |
| 5367 EXPECT_EQ(i, intWrapper->value()); |
| 5368 i++; |
| 5369 } |
| 5370 |
| 5371 // Remove most of the queued objects and have the buffer's start index |
| 5372 // 'point' somewhere into the buffer, just behind the end index. |
| 5373 for (i = 0; i < 50; ++i) |
| 5374 deque->takeFirst(); |
| 5375 |
| 5376 EXPECT_EQ(10u, deque->size()); |
| 5377 i = 0; |
| 5378 for (const auto& intWrapper : *deque) { |
| 5379 EXPECT_EQ(50 + i, intWrapper->value()); |
| 5380 i++; |
| 5381 } |
| 5382 |
| 5383 // Append even more, eventually causing an expansion of the underlying |
| 5384 // buffer once the end index wraps around and reaches the start index. |
| 5385 for (i = 0; i < 70; ++i) |
| 5386 deque->append(IntWrapper::create(60 + i)); |
| 5387 |
| 5388 // Verify that the final buffer expansion copied the start and end segments |
| 5389 // of the old buffer to both ends of the expanded buffer, along with |
| 5390 // re-adjusting both start&end indices in terms of that expanded buffer. |
| 5391 EXPECT_EQ(80u, deque->size()); |
| 5392 i = 0; |
| 5393 for (const auto& intWrapper : *deque) { |
| 5394 EXPECT_EQ(i + 50, intWrapper->value()); |
| 5395 i++; |
| 5396 } |
| 5397 } |
| 5398 |
5350 } // namespace blink | 5399 } // namespace blink |
OLD | NEW |