| 1786 | } |
| 1787 | |
| 1788 | ResultType 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 | |
| 1806 | template<typename TokenT> |
| 1807 | ResultType Array::InsertAt(index_t aIndex, TokenT aValue[], index_t aCount) |
nothing calls this directly
no test coverage detected