Cell APCLocalArray::NvGetKey(const ArrayData* ad, ssize_t pos) { auto a = asApcArray(ad); Variant k = a->m_arr->getKey(pos); auto const tv = k.asTypedValue(); tvIncRefGen(tv); return *tv; }
member_rval::ptr_u APCLocalArray::NvGetStr(const ArrayData* ad, const StringData* key) { auto a = asApcArray(ad); auto index = a->getIndex(key); if (index == -1) return nullptr; return GetValueRef(a, index); }
ArrayData *APCLocalArray::Escalate(const ArrayData* ad) { auto smap = asApcArray(ad); auto ret = smap->loadElems(); assert(!ret->isStatic()); assert(ret->hasExactlyOneRef()); return ret; }
const TypedValue* APCLocalArray::NvGetStr(const ArrayData* ad, const StringData* key) { auto a = asApcArray(ad); auto index = a->getIndex(key); if (index == -1) return nullptr; return GetValueRef(a, index).asTypedValue(); }
bool APCLocalArray::IsVectorData(const ArrayData* ad) { auto a = asApcArray(ad); const auto n = a->size(); for (ssize_t i = 0; i < n; i++) { if (a->getIndex(i) != i) return false; } return true; }
void APCLocalArray::NvGetKey(const ArrayData* ad, TypedValue* out, ssize_t pos) { auto a = asApcArray(ad); Variant k = a->m_arr->getKey(pos); TypedValue* tv = k.asTypedValue(); // copy w/out clobbering out->_count. out->m_type = tv->m_type; out->m_data.num = tv->m_data.num; if (tv->m_type != KindOfInt64) out->m_data.pstr->incRefCount(); }
ArrayData* APCLocalArray::EscalateForSort(ArrayData* ad, SortFunction sf) { auto a = asApcArray(ad); ArrayData* elems = a->loadElems(); ArrayData* ret = elems->escalateForSort(sf); if (ret != elems) { elems->release(); } assert(ret->getCount() == 0); assert(!ret->isStatic()); return ret; }
void APCLocalArray::Release(ArrayData* ad) { assert(ad->hasExactlyOneRef()); auto const a = asApcArray(ad); auto size = a->heapSize(); for (auto tv = a->localCache(), end = tv + a->m_size; tv < end; ++tv) { tvDecRefGen(tv); } a->m_arr->unreference(); MM().removeApcArray(a); MM().objFree(a, size); }
member_rval::ptr_u APCLocalArray::GetValueRef(const ArrayData* adIn, ssize_t pos) { auto const ad = asApcArray(adIn); assert(unsigned(pos) < ad->getSize()); auto const elms = ad->localCache(); auto const tv = &elms[pos]; if (tv->m_type != KindOfUninit) return tv; auto const sv = ad->m_arr->getValue(pos); tvAsVariant(tv) = sv->toLocal(); assert(tv->m_type != KindOfUninit); return tv; }
const Variant& APCLocalArray::GetValueRef(const ArrayData* adIn, ssize_t pos) { auto const ad = asApcArray(adIn); auto const sv = ad->m_arr->getValue(pos); if (LIKELY(ad->m_localCache != nullptr)) { assert(unsigned(pos) < ad->m_arr->capacity()); TypedValue* tv = &ad->m_localCache[pos]; if (tv->m_type != KindOfUninit) { return tvAsCVarRef(tv); } } else { static_assert(KindOfUninit == 0, "must be 0 since we use req::calloc"); unsigned cap = ad->m_arr->capacity(); ad->m_localCache = req::calloc_raw_array<TypedValue>(cap); } auto const tv = &ad->m_localCache[pos]; tvAsVariant(tv) = sv->toLocal(); assert(tv->m_type != KindOfUninit); return tvAsCVarRef(tv); }
ssize_t APCLocalArray::IterEnd(const ArrayData* ad) { auto a = asApcArray(ad); auto n = a->m_size; return n; }
ssize_t APCLocalArray::IterAdvance(const ArrayData* ad, ssize_t prev) { auto a = asApcArray(ad); return a->iterAdvanceImpl(prev); }
member_rval::ptr_u APCLocalArray::NvGetInt(const ArrayData* ad, int64_t k) { auto a = asApcArray(ad); auto index = a->getIndex(k); if (index == -1) return nullptr; return GetValueRef(a, index); }
ssize_t APCLocalArray::IterLast(const ArrayData* ad) { auto a = asApcArray(ad); auto n = a->m_size; return n > 0 ? ssize_t(n - 1) : 0; }
ArrayData* APCLocalArray::EscalateForSort(ArrayData* ad) { auto a = asApcArray(ad); auto ret = a->loadElems()->escalateForSort(); assert(!ret->isStatic()); return ret; }
ssize_t APCLocalArray::IterRewind(const ArrayData* ad, ssize_t prev) { auto a = asApcArray(ad); assert(prev >= 0 && prev < a->m_size); ssize_t next = prev - 1; return next >= 0 ? next : a->m_size; }
const TypedValue* APCLocalArray::NvGetInt(const ArrayData* ad, int64_t k) { auto a = asApcArray(ad); auto index = a->getIndex(k); if (index == -1) return nullptr; return GetValueRef(a, index).asTypedValue(); }
bool APCLocalArray::ExistsInt(const ArrayData* ad, int64_t k) { return asApcArray(ad)->getIndex(k) != -1; }
void APCLocalArray::Release(ArrayData* ad) { assert(ad->hasExactlyOneRef()); auto const a = asApcArray(ad); a->~APCLocalArray(); MM().freeSmallSize(a, sizeof(APCLocalArray)); }
void APCLocalArray::Release(ArrayData* ad) { auto const a = asApcArray(ad); a->~APCLocalArray(); MM().smartFreeSize(a, sizeof(APCLocalArray)); }
bool APCLocalArray::ExistsStr(const ArrayData* ad, const StringData* k) { auto a = asApcArray(ad); return a->getIndex(k) != -1; }