| 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 { |
nothing calls this directly
no test coverage detected