MCPcopy Create free account
hub / github.com/Shannon-Data/ShannonBase / shrink_to_fit

Method shrink_to_fit

include/prealloced_array.h:553–571  ·  view source on GitHub ↗

Requests the container to reduce its capacity to fit its size. */

Source from the content-addressed store, hash-verified

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.

Callers 15

add_elementMethod · 0.45
set_wild_do_tableMethod · 0.45
set_wild_ignore_tableMethod · 0.45
free_string_arrayMethod · 0.45
rewindMethod · 0.45
destroyMethod · 0.45
allocate_blockMethod · 0.45
destroyMethod · 0.45
driverMethod · 0.45
init_check_hostFunction · 0.45
acl_loadFunction · 0.45

Calls 8

~Prealloced_arrayMethod · 0.95
swapFunction · 0.70
beginMethod · 0.65
endMethod · 0.65
sizeClass · 0.50
capacityFunction · 0.50
beginFunction · 0.50
endFunction · 0.50

Tested by

no test coverage detected