aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/util/bufferwriter.cpp
blob: 4477554c0eb0f5df284435013a96c0d39e5d3663 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "bufferwriter.h"

namespace search {

BufferWriter::BufferWriter()
    : _cur(nullptr),
      _end(nullptr),
      _start(nullptr)
{
}

BufferWriter::~BufferWriter() = default;

void
BufferWriter::writeSlow(const void *src, size_t len)
{
    size_t residue = len;
    const char *csrc = static_cast<const char *>(src);
    for (;;) {
        size_t maxLen = freeLen();
        if (residue <= maxLen) {
            writeFast(csrc, residue);
            break;
        }
        if (maxLen != 0) {
            writeFast(csrc, maxLen);
            csrc += maxLen;
            residue -= maxLen;
        }
        flush();
    }
}

} // namespace search