コード例 #1
0
ファイル: u_string.cpp プロジェクト: dreamsxin/neothyne
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;
}
コード例 #2
0
ファイル: u_string.cpp プロジェクト: q66/neothyne
char *string::copy() const {
    const size_t length = size() + 1;
    return (char *)memcpy(STR_MALLOC(length), m_first, length);
}