MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / EnsureCapacity

Method EnsureCapacity

source/script_object.cpp:1788–1804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1786}
1787
1788ResultType Array::EnsureCapacity(index_t aRequired)
1789{
1790 if (mCapacity >= aRequired)
1791 return OK;
1792 // Simple doubling of previous capacity, if that's enough, seems adequate.
1793 // Otherwise, allocate exactly the amount required with no room to spare.
1794 // v1 Object doubled in capacity when needed to add a new field, but started
1795 // at 4 and did not allocate any extra space when inserting with InsertAt or
1796 // Push. By contrast, this approach:
1797 // 1) Wastes no space in the possibly common case where Array::InsertAt is
1798 // called exactly once (such as when constructing the Array).
1799 // 2) Expands exponentially if Push is being used repeatedly, which should
1800 // perform much better than expanding by 1 each time.
1801 if (aRequired < (mCapacity << 1))
1802 aRequired = (mCapacity << 1);
1803 return SetCapacity(aRequired);
1804}
1805
1806template<typename TokenT>
1807ResultType Array::InsertAt(index_t aIndex, TokenT aValue[], index_t aCount)

Callers

nothing calls this directly

Calls 1

SetCapacityFunction · 0.85

Tested by

no test coverage detected