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

Method impl

Fleece/Core/Array.cc:28–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27
28 __hot
29 Array::impl::impl(const Value* v) noexcept {
30 if (_usuallyFalse(v == nullptr)) {
31 _first = nullptr;
32 _width = kNarrow;
33 _count = 0;
34 } else if (_usuallyTrue(!v->isMutable())) {
35 // Normal immutable case:
36 _first = (const Value*)(&v->_byte[2]);
37 _width = v->isWideArray() ? kWide : kNarrow;
38 _count = v->countValue();
39 if (_usuallyFalse(_count == kLongArrayCount)) {
40 // Long count is stored as a varint:
41 uint32_t extraCount;
42 size_t countSize = GetUVarInt32(slice(_first, 10), &extraCount);
43 if (_usuallyTrue(countSize > 0))
44 _count += extraCount;
45 else
46 _count = 0; // invalid data, but I'm not allowed to throw an exception
47 _first = offsetby(_first, countSize + (countSize & 1));
48 }
49 } else {
50 // Mutable Array or Dict:
51 auto mcoll = (HeapCollection*)HeapValue::asHeapValue(v);
52 HeapArray *mutArray;
53 if (v->tag() == kArrayTag) {
54 mutArray = (HeapArray*)mcoll;
55 _count = mutArray->count();
56 } else {
57 mutArray = ((HeapDict*)mcoll)->kvArray();
58 _count = mutArray->count() / 2;
59 }
60 _first = _count ? (const Value*)mutArray->first() : nullptr;
61 _width = sizeof(ValueSlot);
62 }
63 }
64
65 __hot
66 const Value* Array::impl::deref(const Value *v) const noexcept {

Callers

nothing calls this directly

Calls 10

GetUVarInt32Function · 0.85
sliceClass · 0.85
offsetbyFunction · 0.85
isWideArrayMethod · 0.80
countValueMethod · 0.80
kvArrayMethod · 0.80
firstMethod · 0.80
isMutableMethod · 0.45
tagMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected