| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_CONTAINERS_SMALL_MAP_H_ | 5 #ifndef BASE_CONTAINERS_SMALL_MAP_H_ |
| 6 #define BASE_CONTAINERS_SMALL_MAP_H_ | 6 #define BASE_CONTAINERS_SMALL_MAP_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 size_ = 0; | 510 size_ = 0; |
| 511 } | 511 } |
| 512 | 512 |
| 513 // Invalidates iterators. | 513 // Invalidates iterators. |
| 514 void erase(const iterator& position) { | 514 void erase(const iterator& position) { |
| 515 if (size_ >= 0) { | 515 if (size_ >= 0) { |
| 516 int i = position.array_iter_ - array_; | 516 int i = position.array_iter_ - array_; |
| 517 array_[i].Destroy(); | 517 array_[i].Destroy(); |
| 518 --size_; | 518 --size_; |
| 519 if (i != size_) { | 519 if (i != size_) { |
| 520 array_[i].Init(*array_[size_]); | 520 array_[i].InitFromMove(std::move(array_[size_])); |
| 521 array_[size_].Destroy(); | 521 array_[size_].Destroy(); |
| 522 } | 522 } |
| 523 } else { | 523 } else { |
| 524 map_->erase(position.hash_iter_); | 524 map_->erase(position.hash_iter_); |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 | 527 |
| 528 size_t erase(const key_type& key) { | 528 size_t erase(const key_type& key) { |
| 529 iterator iter = find(key); | 529 iterator iter = find(key); |
| 530 if (iter == end()) return 0u; | 530 if (iter == end()) return 0u; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 ManualConstructor<value_type> dummy_; | 587 ManualConstructor<value_type> dummy_; |
| 588 ManualConstructor<value_type> array_[kArraySize]; | 588 ManualConstructor<value_type> array_[kArraySize]; |
| 589 ManualConstructor<NormalMap> map_; | 589 ManualConstructor<NormalMap> map_; |
| 590 }; | 590 }; |
| 591 | 591 |
| 592 void ConvertToRealMap() { | 592 void ConvertToRealMap() { |
| 593 // Move the current elements into a temporary array. | 593 // Move the current elements into a temporary array. |
| 594 ManualConstructor<value_type> temp_array[kArraySize]; | 594 ManualConstructor<value_type> temp_array[kArraySize]; |
| 595 | 595 |
| 596 for (int i = 0; i < kArraySize; i++) { | 596 for (int i = 0; i < kArraySize; i++) { |
| 597 temp_array[i].Init(*array_[i]); | 597 temp_array[i].InitFromMove(std::move(array_[i])); |
| 598 array_[i].Destroy(); | 598 array_[i].Destroy(); |
| 599 } | 599 } |
| 600 | 600 |
| 601 // Initialize the map. | 601 // Initialize the map. |
| 602 size_ = -1; | 602 size_ = -1; |
| 603 functor_(&map_); | 603 functor_(&map_); |
| 604 | 604 |
| 605 // Insert elements into it. | 605 // Insert elements into it. |
| 606 for (int i = 0; i < kArraySize; i++) { | 606 for (int i = 0; i < kArraySize; i++) { |
| 607 map_->insert(*temp_array[i]); | 607 map_->insert(std::move(*temp_array[i])); |
| 608 temp_array[i].Destroy(); | 608 temp_array[i].Destroy(); |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 | 611 |
| 612 // Helpers for constructors and destructors. | 612 // Helpers for constructors and destructors. |
| 613 void InitFrom(const SmallMap& src) { | 613 void InitFrom(const SmallMap& src) { |
| 614 functor_ = src.functor_; | 614 functor_ = src.functor_; |
| 615 size_ = src.size_; | 615 size_ = src.size_; |
| 616 if (src.size_ >= 0) { | 616 if (src.size_ >= 0) { |
| 617 for (int i = 0; i < size_; i++) { | 617 for (int i = 0; i < size_; i++) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 644 typename Functor> | 644 typename Functor> |
| 645 inline bool SmallMap<NormalMap, kArraySize, EqualKey, | 645 inline bool SmallMap<NormalMap, kArraySize, EqualKey, |
| 646 Functor>::iterator::operator!=( | 646 Functor>::iterator::operator!=( |
| 647 const const_iterator& other) const { | 647 const const_iterator& other) const { |
| 648 return other != *this; | 648 return other != *this; |
| 649 } | 649 } |
| 650 | 650 |
| 651 } // namespace base | 651 } // namespace base |
| 652 | 652 |
| 653 #endif // BASE_CONTAINERS_SMALL_MAP_H_ | 653 #endif // BASE_CONTAINERS_SMALL_MAP_H_ |
| OLD | NEW |