HOT_FUNC Variant ArrayIter::second() { if (hasVector()) { c_Vector* vec = getVector(); if (UNLIKELY(m_versionNumber != vec->getVersionNumber())) { throw_collection_modified(); } return tvAsCVarRef(vec->at(m_pos)); } if (hasMap()) { c_Map* mp = getMap(); if (UNLIKELY(m_versionNumber != mp->getVersionNumber())) { throw_collection_modified(); } return mp->iter_value(m_pos); } if (hasStableMap()) { c_StableMap* smp = getStableMap(); if (UNLIKELY(m_versionNumber != smp->getVersionNumber())) { throw_collection_modified(); } return smp->iter_value(m_pos); } if (hasObject()) { ObjectData* obj = getObject(); return obj->o_invoke(s_current, Array()); } assert(hasArrayData()); assert(m_pos != ArrayData::invalid_index); const ArrayData* ad = getArrayData(); assert(ad); return ad->getValue(m_pos); }
int main() { int intArray[MAX_ARR_SIZE]; int numElm = 0; int result = 0; int choice, rc; StackType stack; st_init(&stack); //initialize the stack rc = getArrayData(intArray, &numElm); if (rc < 0) exit(1); printf("\nHow would like to sum the elements?\n"); printf(" (1) iteratively\n"); printf(" (2) recursively\n"); scanf("%d", &choice); switch (choice) { case 1: sumIterative(numElm, intArray, &result, &stack); printf("Sum is %d\n", result); break; case 2: sumRecursive(numElm, intArray, &result, &stack); printf("Sum is %d\n", result); } return 0; }
HOT_FUNC CVarRef ArrayIter::secondRef() { if (!hasArrayData()) { throw FatalErrorException("taking reference on iterator objects"); } assert(hasArrayData()); assert(m_pos != ArrayData::invalid_index); const ArrayData* ad = getArrayData(); assert(ad); return ad->getValueRef(m_pos); }
HOT_FUNC ArrayIter::~ArrayIter() { if (hasArrayData()) { const ArrayData* ad = getArrayData(); if (ad) decRefArr(const_cast<ArrayData*>(ad)); return; } ObjectData* obj = getRawObject(); assert(obj); decRefObj(obj); }
void ArrayIter::reset() { if (hasArrayData()) { const ArrayData* ad = getArrayData(); m_data = NULL; if (ad) decRefArr(const_cast<ArrayData*>(ad)); return; } ObjectData* obj = getRawObject(); m_data = NULL; assert(obj); decRefObj(obj); }
HOT_FUNC ArrayIter::~ArrayIter() { if (hasArrayData()) { const ArrayData* ad = getArrayData(); if (ad) decRefArr(const_cast<ArrayData*>(ad)); return; } ObjectData* obj = getRawObject(); ASSERT(obj); if (obj->decRefCount() == 0) { const_cast<ObjectData*>(obj)->release(); } }