Exemplo n.º 1
0
int64 HphpMap::hash(CVarRef s) {
  int64 hash;
  switch (s.getType()) {
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64:
    hash = hash_int64(s.toInt64());
    break;
  case LiteralString:
    {
      const char* d = s.getLiteralString();
      hash = hash_string(d, strlen(d));
    }
    break;
  case KindOfString:
    {
      StringData *st = s.getStringData();
      hash = hash_string(st->data(), st->size());
    }
    break;
  default:
    ASSERT(false);
    return 0;
  }
  return hash;
}
Exemplo n.º 2
0
int hphp_ffi_exportVariant(CVarRef v, void** result) {
  switch (v.getType()) {
  case KindOfNull:    return 0;
  case KindOfBoolean: *result = (void*)v.toBoolean(); return 1;
  case KindOfByte:
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64: {
    *result = (void*)v.toInt64();
    return 2;
  }
  case KindOfDouble: {
    union {
      double d;
      void* p;
    } u;
    u.d = v.toDouble();
    *result = u.p;
    return 3;
  }
  case LiteralString: *result = (void*)v.getLiteralString(); return 4;
  case KindOfString: {
    StringData *sd = v.getStringData();
    sd->incRefCount();
    *result = (void*)sd;
    return 5;
  }
  case KindOfArray: {
    ArrayData *ad = v.getArrayData();
    ad->incRefCount();
    *result = (void*)ad;
    return 6;
  }
  case KindOfObject: {
    ObjectData *od = v.getObjectData();
    od->incRefCount();
    *result = (void*)od;
    return 7;
  }
  default:
    ASSERT(false);
    return 0;
  }
}
Exemplo n.º 3
0
bool HphpMap::same(CVarRef s1, CVarRef s2) {
  DataType t1 = s1.getType();
  DataType t2 = s2.getType();
  switch (t1) {
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64:
    switch (t2) {
    case KindOfInt16:
    case KindOfInt32:
    case KindOfInt64:
      break;
    default:
      return false;
    }
    break;
  case LiteralString:
  case KindOfString:
    switch (t2) {
    case LiteralString:
    case KindOfString:
      break;
    default:
      return false;
    }
    break;
  default:
    ASSERT(false);
    if (t1 != t2) return false;
    break;
  }

  switch (t1) {
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64:
    return s1.toInt64() == s2.toInt64();
  default:
    const char* s1d;
    uint64 s1l;
    const char* s2d;
    uint64 s2l;
    if (t1 == LiteralString) {
      s1d = s1.getLiteralString();
      s1l = strlen(s1d);
    } else {
      StringData *s1data = s1.getStringData();
      s1d = s1data->data();
      s1l = s1data->size();
    }
    if (t2 == LiteralString) {
      s2d = s2.getLiteralString();
      s2l = strlen(s2d);
    } else {
      StringData *s2data = s2.getStringData();
      s2d = s2data->data();
      s2l = s2data->size();
    }
    return string_strcmp(s1d, s1l, s2d, s2l) == 0;
  }
}