void string::reserve(size_t capacity) { if (m_first + capacity + 1 <= m_capacity) return; const size_t size = m_last - m_first; char *newfirst = nullptr; if (m_first == m_buffer) { newfirst = STR_MALLOC(capacity + 1); memcpy(newfirst, m_first, size + 1); } else { newfirst = STR_REALLOC(m_first, capacity + 1); } m_first = newfirst; m_last = newfirst + size; m_capacity = m_first + capacity; }
char *string::copy() const { const size_t length = size() + 1; return (char *)memcpy(STR_MALLOC(length), m_first, length); }