Requests the container to reduce its capacity to fit its size. */
| 551 | Requests the container to reduce its capacity to fit its size. |
| 552 | */ |
| 553 | void shrink_to_fit() { |
| 554 | // Cannot shrink the pre-allocated array. |
| 555 | if (using_inline_buffer()) return; |
| 556 | // No point in swapping. |
| 557 | if (size() == capacity()) return; |
| 558 | Prealloced_array tmp(m_psi_key, begin(), end()); |
| 559 | if (size() <= Prealloc) { |
| 560 | /* |
| 561 | The elements fit in the pre-allocated array. Destruct the |
| 562 | heap-allocated array in this, and copy the elements into the |
| 563 | pre-allocated array. |
| 564 | */ |
| 565 | this->~Prealloced_array(); |
| 566 | new (this) Prealloced_array(tmp.m_psi_key, tmp.begin(), tmp.end()); |
| 567 | } else { |
| 568 | // Both this and tmp have a heap-allocated array. Swap pointers. |
| 569 | swap(tmp); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | Resizes the container so that it contains n elements. |
no test coverage detected