Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1957)

Unified Diff: Source/platform/heap/HeapTest.cpp

Issue 835453002: Add missing buffer reorg on Deque buffer expansion. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Scale back added comments in Deque.h Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/wtf/Deque.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/HeapTest.cpp
diff --git a/Source/platform/heap/HeapTest.cpp b/Source/platform/heap/HeapTest.cpp
index 6c7f071a9fb7bab7a3fbc34f9f1ed2b223d3277d..b856c318bf0aea3877ae4dbf2c7d811142506242 100644
--- a/Source/platform/heap/HeapTest.cpp
+++ b/Source/platform/heap/HeapTest.cpp
@@ -5347,4 +5347,53 @@ TEST(HeapTest, TraceDeepEagerly)
#endif
}
+TEST(HeapTest, DequeExpand)
+{
+ // Test expansion of a HeapDeque<>'s buffer.
+
+ typedef HeapDeque<Member<IntWrapper>> IntDeque;
+
+ Persistent<IntDeque> deque = new IntDeque();
+
+ // Append a sequence, bringing about repeated expansions of the
+ // deque's buffer.
+ int i = 0;
+ for (; i < 60; ++i)
+ deque->append(IntWrapper::create(i));
+
+ EXPECT_EQ(60u, deque->size());
+ i = 0;
+ for (const auto& intWrapper : *deque) {
+ EXPECT_EQ(i, intWrapper->value());
+ i++;
+ }
+
+ // Remove most of the queued objects and have the buffer's start index
+ // 'point' somewhere into the buffer, just behind the end index.
+ for (i = 0; i < 50; ++i)
+ deque->takeFirst();
+
+ EXPECT_EQ(10u, deque->size());
+ i = 0;
+ for (const auto& intWrapper : *deque) {
+ EXPECT_EQ(50 + i, intWrapper->value());
+ i++;
+ }
+
+ // Append even more, eventually causing an expansion of the underlying
+ // buffer once the end index wraps around and reaches the start index.
+ for (i = 0; i < 70; ++i)
+ deque->append(IntWrapper::create(60 + i));
+
+ // Verify that the final buffer expansion copied the start and end segments
+ // of the old buffer to both ends of the expanded buffer, along with
+ // re-adjusting both start&end indices in terms of that expanded buffer.
+ EXPECT_EQ(80u, deque->size());
+ i = 0;
+ for (const auto& intWrapper : *deque) {
+ EXPECT_EQ(i + 50, intWrapper->value());
+ i++;
+ }
+}
+
} // namespace blink
« no previous file with comments | « no previous file | Source/wtf/Deque.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698