MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / reserve

Method reserve

source/core/StarByteArray.cpp:83–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83void ByteArray::reserve(size_t newCapacity) {
84 if (newCapacity > m_capacity) {
85 if (!m_data) {
86 auto newMem = (char*)Star::malloc(newCapacity);
87 if (!newMem)
88 throw MemoryException::format("Could not set new ByteArray capacity {}\n", newCapacity);
89 m_data = newMem;
90 m_capacity = newCapacity;
91 } else {
92 newCapacity = max({m_capacity * 2, newCapacity, (size_t)8});
93 auto newMem = (char*)Star::realloc(m_data, newCapacity);
94 if (!newMem)
95 throw MemoryException::format("Could not set new ByteArray capacity {}\n", newCapacity);
96 m_data = newMem;
97 m_capacity = newCapacity;
98 }
99 }
100}
101
102void ByteArray::resize(size_t size, char f) {
103 if (m_size == size)

Callers 1

withReserveMethod · 0.45

Calls 3

mallocFunction · 0.70
formatFunction · 0.70
reallocFunction · 0.70

Tested by

no test coverage detected