示例#1
0
void ArrayIter::objInit(ObjectData *obj) {
    assert(obj);
    setObject(obj);
    if (incRef) {
        obj->incRefCount();
    }
    if (!obj->isCollection()) {
        assert(obj->o_instanceof(s_Iterator));
        obj->o_invoke(s_rewind, Array());
    } else {
        if (hasVector()) {
            c_Vector* vec = getVector();
            m_versionNumber = vec->getVersionNumber();
            m_pos = 0;
        } else if (hasMap()) {
            c_Map* mp = getMap();
            m_versionNumber = mp->getVersionNumber();
            m_pos = mp->iter_begin();
        } else if (hasStableMap()) {
            c_StableMap* smp = getStableMap();
            m_versionNumber = smp->getVersionNumber();
            m_pos = smp->iter_begin();
        } else {
            assert(false);
        }
    }
}
示例#2
0
void ArrayIter::secondHelper(Variant & v) {
    if (hasVector()) {
        c_Vector* vec = getVector();
        if (UNLIKELY(m_versionNumber != vec->getVersionNumber())) {
            throw_collection_modified();
        }
        v = tvAsCVarRef(vec->at(m_pos));
        return;
    }
    if (hasMap()) {
        c_Map* mp = getMap();
        if (UNLIKELY(m_versionNumber != mp->getVersionNumber())) {
            throw_collection_modified();
        }
        v = mp->iter_value(m_pos);
        return;
    }
    if (hasStableMap()) {
        c_StableMap* smp = getStableMap();
        if (UNLIKELY(m_versionNumber != smp->getVersionNumber())) {
            throw_collection_modified();
        }
        v = smp->iter_value(m_pos);
        return;
    }
    assert(hasObject());
    ObjectData* obj = getObject();
    v = obj->o_invoke(s_current, Array());
}
示例#3
0
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);
}
示例#4
0
void ArrayIter::nextHelper() {
    if (hasVector()) {
        m_pos++;
        return;
    }
    if (hasMap()) {
        assert(m_pos != 0);
        c_Map* mp = getMap();
        if (UNLIKELY(m_versionNumber != mp->getVersionNumber())) {
            throw_collection_modified();
        }
        m_pos = mp->iter_next(m_pos);
        return;
    }
    if (hasStableMap()) {
        assert(m_pos != 0);
        c_StableMap* smp = getStableMap();
        if (UNLIKELY(m_versionNumber != smp->getVersionNumber())) {
            throw_collection_modified();
        }
        m_pos = smp->iter_next(m_pos);
        return;
    }
    assert(hasObject());
    ObjectData* obj = getObject();
    obj->o_invoke(s_next, Array());
}
示例#5
0
void ArrayIter::objInit(ObjectData *obj, bool rewind /* = true */) {
  ASSERT(obj);
  setObject(obj);
  if (incRef) {
    obj->incRefCount();
  }
  if (!obj->isCollection()) {
    ASSERT(obj->o_instanceof(s_Iterator));
    if (rewind) {
      obj->o_invoke(s_rewind, Array());
    }
    // If it is from IteratorAggregate, there is no need to rewind.
  } else {
    if (hasVector()) {
      c_Vector* vec = getVector();
      m_versionNumber = vec->getVersionNumber();
      m_pos = 0;
    } else if (hasMap()) {
      c_Map* mp = getMap();
      m_versionNumber = mp->getVersionNumber();
      m_pos = mp->iter_begin();
    } else if (hasStableMap()) {
      c_StableMap* smp = getStableMap();
      m_versionNumber = smp->getVersionNumber();
      m_pos = smp->iter_begin();
    } else {
      ASSERT(false);
    }
  }
}
示例#6
0
Variant ArrayIter::firstHelper() {
    if (hasVector()) {
        return m_pos;
    }
    if (hasMap()) {
        assert(m_pos != 0);
        c_Map* mp = getMap();
        if (UNLIKELY(m_versionNumber != mp->getVersionNumber())) {
            throw_collection_modified();
        }
        return mp->iter_key(m_pos);
    }
    if (hasStableMap()) {
        assert(m_pos != 0);
        c_StableMap* smp = getStableMap();
        if (UNLIKELY(m_versionNumber != smp->getVersionNumber())) {
            throw_collection_modified();
        }
        return smp->iter_key(m_pos);
    }
    assert(hasObject());
    ObjectData* obj = getObject();
    return obj->o_invoke(s_key, Array());
}