Example #1
0
CVarRef Array::add(CVarRef key, CVarRef v, bool isKey /* = false */) {
  if (key.getRawType() == KindOfInt64) {
    return addImpl(key.getNumData(), v);
  }
  if (isKey) return addImpl(key, v);
  VarNR k(key.toKey());
  if (!k.isNull()) {
    return addImpl(k, v);
  }
  return Variant::lvalBlackHole();
}
Example #2
0
MapVariant::MapVariant(const VectorVariant *src, CVarRef k, CVarRef v) :
    m_nextIndex(0), m_keys(NULL) {
    ASSERT(src);
    ASSERT(src->getIndex(k) < 0);
    const HphpVector<Variant *> &srcElems = src->getElems();
    m_nextIndex = srcElems.size();
    for (int i = 0; i < m_nextIndex; i++) {
        m_map[Variant((int64)i)] = i;
    }
    m_elems.reserve(m_nextIndex + 1);
    ArrayFuncs::append(m_elems, srcElems);
    insertKey(k.toKey());
    m_elems.push_back(ArrayFuncs::element(v));
}
Example #3
0
void Array::remove(CVarRef key) {
  switch(key.getType()) {
  case KindOfBoolean:
  case KindOfInt64:
    removeImpl(key.toInt64());
    return;
  default:
    break;
  }
  VarNR k(key.toKey());
  if (!k.isNull()) {
    removeImpl(k);
  }
}
bool Array::exists(CVarRef key, bool isKey /* = false */) const {
    switch(key.getType()) {
    case KindOfBoolean:
    case KindOfInt64:
        return existsImpl(key.toInt64());
    default:
        break;
    }
    if (isKey) return existsImpl(key);
    VarNR k(key.toKey());
    if (!k.isNull()) {
        return existsImpl(k);
    }
    return false;
}
Example #5
0
MapVariant::MapVariant(const MapVariant *src, CVarRef k, CVarRef v) :
    m_nextIndex(0), m_keys(NULL) {
    ASSERT(src);
    m_map = src->m_map;
    m_nextIndex = src->m_nextIndex;
    int index = src->getIndex(k);
    if (index >= 0) {
        ArrayFuncs::append(m_elems, src->m_elems);
        ArrayFuncs::set(m_elems, index, ArrayFuncs::element(v));
    } else {
        m_elems.reserve(src->m_elems.size() + 1);
        ArrayFuncs::append(m_elems, src->m_elems);
        insertKey(k.toKey());
        m_elems.push_back(ArrayFuncs::element(v));
    }
}
Example #6
0
void Array::remove(CVarRef key, int64 prehash /* = -1 */) {
  switch(key.getType()) {
  case KindOfBoolean:
  case KindOfByte:
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64:
    removeImpl(key.toInt64(), prehash);
    return;
  default:
    break;
  }
  Variant k = key.toKey();
  if (!k.isNull()) {
    removeImpl(k, prehash);
  }
}
Example #7
0
bool Array::exists(CVarRef key, int64 prehash /* = -1 */) const {
  switch(key.getType()) {
  case KindOfBoolean:
  case KindOfByte:
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64:
    return existsImpl(key.toInt64(), prehash);
  default:
    break;
  }
  Variant k = key.toKey();
  if (!k.isNull()) {
    return existsImpl(k, prehash);
  }
  return false;
}
Example #8
0
CVarRef Array::set(CVarRef key, CVarRef v, int64 prehash /* = -1 */) {
  switch(key.getType()) {
  case KindOfBoolean:
  case KindOfByte:
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64:
    return setImpl(key.toInt64(), v, prehash);
  default:
    break;
  }
  Variant k = key.toKey();
  if (!k.isNull()) {
    return setImpl(k, v, prehash);
  }
  return null_variant;
}
Example #9
0
Variant Array::rvalAt(CVarRef key, int64 prehash /* = -1 */) const {
  if (!m_px) return null;

  switch(key.getType()) {
  case KindOfBoolean:
  case KindOfByte:
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64:
    return m_px->get(key.toInt64(), prehash);
  default:
    break;
  }
  Variant k = key.toKey();
  if (!k.isNull()) {
    return m_px->get(k, prehash);
  }
  return null;
}
Array Array::Create(CVarRef name, CVarRef var) {
    return ArrayData::Create(name.isString() ? name.toKey() : name, var);
}