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

Method writeTo

Fleece/Tree/MutableNode.hh:264–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262
263
264 Interior writeTo(Encoder &enc) {
265 unsigned n = childCount();
266
267 // `nodes` is an in-memory staging area for the child nodes I'll write.
268 // The offsets in it are absolute positions in the encoded output,
269 // except for ones that are bitmaps.
270 TempArray(nodes, Node, n);
271
272 // Write interior nodes, then leaf node Values, then leaf node keys.
273 // This keeps the keys near me, for better locality of reference.
274 for (unsigned i = 0; i < n; ++i) {
275 if (!_children[i].isLeaf())
276 nodes[i] = _children[i].writeTo(enc);
277 }
278 for (unsigned i = 0; i < n; ++i) {
279 if (_children[i].isLeaf())
280 nodes[i].leaf._valueOffset = _children[i].writeTo(enc, false);
281 }
282 for (unsigned i = 0; i < n; ++i) {
283 if (_children[i].isLeaf())
284 nodes[i].leaf._keyOffset = _children[i].writeTo(enc, true);
285 }
286
287 // Convert the Nodes' absolute positions into offsets:
288 const offset_t childrenPos = (offset_t)enc.nextWritePos();
289 auto curPos = childrenPos;
290 for (unsigned i = 0; i < n; ++i) {
291 auto &node = nodes[i];
292 if (_children[i].isLeaf())
293 node.leaf.makeRelativeTo(curPos);
294 else
295 node.interior.makeRelativeTo(curPos);
296 curPos += sizeof(nodes[i]);
297 }
298
299 // Write the list of children, and return its position & my bitmap:
300 enc.writeRaw({nodes, n * sizeof(nodes[0])});
301 return Interior(bitmap_t(_bitmap), childrenPos);
302 }
303
304
305 offset_t writeRootTo(Encoder &enc) {

Callers

nothing calls this directly

Calls 6

InteriorClass · 0.70
isLeafMethod · 0.45
writeToMethod · 0.45
nextWritePosMethod · 0.45
makeRelativeToMethod · 0.45
writeRawMethod · 0.45

Tested by

no test coverage detected