| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 | 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 iter = map.find(MoveOnly(13)); | 471 iter = map.find(MoveOnly(13)); |
| 472 EXPECT_TRUE(iter == map.end()); | 472 EXPECT_TRUE(iter == map.end()); |
| 473 | 473 |
| 474 map.clear(); | 474 map.clear(); |
| 475 } | 475 } |
| 476 | 476 |
| 477 class CountCopy final { | 477 class CountCopy final { |
| 478 public: | 478 public: |
| 479 CountCopy() : m_counter(nullptr) { } | 479 CountCopy() : m_counter(nullptr) { } |
| 480 explicit CountCopy(int& counter) : m_counter(&counter) { } | 480 explicit CountCopy(int& counter) : m_counter(&counter) { } |
| 481 CountCopy(const CountCopy& other) : m_counter(other.m_counter) | 481 CountCopy(const CountCopy& other) |
| 482 : m_counter(other.m_counter) |
| 482 { | 483 { |
| 483 if (m_counter) | 484 if (m_counter) |
| 484 ++*m_counter; | 485 ++*m_counter; |
| 485 } | 486 } |
| 487 CountCopy& operator=(const CountCopy& other) |
| 488 { |
| 489 m_counter = other.m_counter; |
| 490 if (m_counter) |
| 491 ++*m_counter; |
| 492 return *this; |
| 493 } |
| 486 | 494 |
| 487 private: | 495 private: |
| 488 int* m_counter; | 496 int* m_counter; |
| 489 }; | 497 }; |
| 490 | 498 |
| 491 TEST(HashMapTest, MoveShouldNotMakeCopy) | 499 TEST(HashMapTest, MoveShouldNotMakeCopy) |
| 492 { | 500 { |
| 493 HashMap<int, CountCopy> map; | 501 HashMap<int, CountCopy> map; |
| 494 int counter = 0; | 502 int counter = 0; |
| 495 map.add(1, CountCopy(counter)); | 503 map.add(1, CountCopy(counter)); |
| 496 | 504 |
| 497 HashMap<int, CountCopy> other(map); | 505 HashMap<int, CountCopy> other(map); |
| 498 counter = 0; | 506 counter = 0; |
| 499 map = std::move(other); | 507 map = std::move(other); |
| 500 EXPECT_EQ(0, counter); | 508 EXPECT_EQ(0, counter); |
| 501 | 509 |
| 502 counter = 0; | 510 counter = 0; |
| 503 HashMap<int, CountCopy> yetAnother(std::move(map)); | 511 HashMap<int, CountCopy> yetAnother(std::move(map)); |
| 504 EXPECT_EQ(0, counter); | 512 EXPECT_EQ(0, counter); |
| 505 } | 513 } |
| 506 | 514 |
| 507 } // anonymous namespace | 515 } // anonymous namespace |
| 508 | 516 |
| 509 } // namespace WTF | 517 } // namespace WTF |
| OLD | NEW |