aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/tempbuf.cpp
blob: 801a1fabb056cf10f50012d316ef252fbf61fe27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "tempbuf.h"

namespace {
    static inline size_t Next(size_t size) noexcept {
        return size * 2;
    }
}

void TTempBufOutput::DoWrite(const void* data, size_t len) {
    if (Y_LIKELY(len <= Left())) {
        Append(data, len);
    } else {
        const size_t filled = Filled();

        TTempBuf buf(Next(filled + len));

        buf.Append(Data(), filled);
        buf.Append(data, len);

        static_cast<TTempBuf&>(*this) = buf;
    }
}