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

Side by Side Diff: third_party/WebKit/Source/wtf/DequeTest.cpp

Issue 1846473002: WTF: Implement move of Deques. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/Deque.h ('k') | third_party/WebKit/Source/wtf/HashMapTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 EXPECT_EQ(0u, deque.size()); 559 EXPECT_EQ(0u, deque.size());
560 560
561 deque.append(Pointer(new int(42))); 561 deque.append(Pointer(new int(42)));
562 deque[0] = Pointer(new int(24)); 562 deque[0] = Pointer(new int(24));
563 ASSERT_EQ(1u, deque.size()); 563 ASSERT_EQ(1u, deque.size());
564 EXPECT_EQ(24, *deque[0]); 564 EXPECT_EQ(24, *deque[0]);
565 565
566 deque.clear(); 566 deque.clear();
567 } 567 }
568 568
569 class CountCopy final {
570 public:
571 explicit CountCopy(int* counter = nullptr) : m_counter(counter) { }
572 CountCopy(const CountCopy& other)
573 : m_counter(other.m_counter)
574 {
575 if (m_counter)
576 ++*m_counter;
577 }
578 CountCopy& operator=(const CountCopy& other)
579 {
580 m_counter = other.m_counter;
581 if (m_counter)
582 ++*m_counter;
583 return *this;
584 }
585
586 private:
587 int* m_counter;
588 };
589
590 TEST(DequeTest, MoveShouldNotMakeCopy)
591 {
592 // Because data in inline buffer may be swapped or moved individually, we fo rce the creation of out-of-line buffer
593 // so we can make sure there's no element-wise copy/move.
594 Deque<CountCopy, 1> deque;
595 int counter = 0;
596 deque.append(CountCopy(&counter));
597 deque.append(CountCopy(&counter));
598
599 Deque<CountCopy, 1> other(deque);
600 counter = 0;
601 deque = std::move(other); // Move assignment.
602 EXPECT_EQ(0, counter);
603
604 counter = 0;
605 Deque<CountCopy, 1> yetAnother(std::move(deque)); // Move construction.
606 EXPECT_EQ(0, counter);
607 }
608
569 } // anonymous namespace 609 } // anonymous namespace
570 610
571 } // namespace WTF 611 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/Deque.h ('k') | third_party/WebKit/Source/wtf/HashMapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698