MCPcopy Create free account
hub / github.com/couchbase/fleece / writeToNewChunk

Method writeToNewChunk

Fleece/Support/Writer.cc:126–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124
125
126 void* Writer::writeToNewChunk(const void* dataOrNull, size_t length) {
127 // If we got here, a call to `write` or `reserveSpace` would not fit in the current chunk
128 if (_outputFile) {
129 flush();
130 if (length > _chunkSize) {
131 freeChunk(_chunks.back());
132 _chunks.clear();
133 addChunk(length);
134 }
135 _length -= _available.size;
136 _available = _chunks[0];
137 _length += _available.size;
138 } else {
139 if (_usuallyTrue(_chunkSize <= 64*1024))
140 _chunkSize *= 2;
141 addChunk(std::max(length, _chunkSize));
142 }
143
144 // Now that we have room, write:
145 auto result = (void*)_available.buf;
146 if (dataOrNull)
147 memcpy((void*)_available.buf, dataOrNull, length);
148 _available.moveStart(length);
149 return result;
150 }
151
152
153 void Writer::flush() {

Callers

nothing calls this directly

Calls 2

moveStartMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected