bool ArrayData::hasInternalReference(PointerSet &vars, bool ds /* = false */) const { if (isSharedMap()) return false; for (ArrayIter iter(this); iter; ++iter) { CVarRef var = iter.secondRef(); if (var.isReferenced()) { Variant *pvar = var.getRefData(); if (vars.find(pvar) != vars.end()) { return true; } vars.insert(pvar); } if (var.isObject()) { ObjectData *pobj = var.getObjectData(); if (vars.find(pobj) != vars.end()) { return true; } vars.insert(pobj); if (ds && pobj->o_instanceof("Serializable")) { return true; } if (pobj->hasInternalReference(vars, ds)) { return true; } } else if (var.isArray() && var.getArrayData()->hasInternalReference(vars, ds)) { return true; } } return false; }
void ArrayData::getChildren(std::vector<TypedValue *> &out) { if (isSharedMap()) { SharedMap *sm = static_cast<SharedMap *>(this); sm->getChildren(out); return; } for (ssize_t pos = iter_begin(); pos != ArrayData::invalid_index; pos = iter_advance(pos)) { TypedValue *tv = nvGetValueRef(pos); out.push_back(tv); } }
HOT_FUNC void ArrayData::release() { if (isHphpArray()) { HphpArray* that = static_cast<HphpArray*>(this); that->release(); return; } if (isSharedMap()) { SharedMap* that = static_cast<SharedMap*>(this); that->release(); return; } if (isArrayShell()) { auto that = static_cast<ArrayShell*>(this); that->release(); return; } assert(m_kind == kNameValueTableWrapper); // NameValueTableWrapper: nop. }
bool ArrayData::hasInternalReference(PointerSet &vars, bool ds /* = false */) const { if (isSharedMap()) return false; for (ArrayIter iter(this); iter; ++iter) { CVarRef var = iter.secondRef(); if (var.isReferenced()) { Variant *pvar = var.getVariantData(); if (vars.find(pvar) != vars.end()) { return true; } vars.insert(pvar); } if (var.isObject()) { ObjectData *pobj = var.getObjectData(); if (vars.find(pobj) != vars.end()) { return true; } vars.insert(pobj); if (pobj->o_instanceof("Serializable")) { if (ds) { // We want to detect Serializable object as well return true; } else { // Serializable object does not have internal reference issue return false; } } if (pobj->o_toArray().get()->hasInternalReference(vars, ds)) { return true; } } else if (var.isArray() && var.getArrayData()->hasInternalReference(vars, ds)) { return true; } } return false; }