示例#1
0
ALWAYS_INLINE
MixedArray* PackedArray::ToMixedHeader(const ArrayData* old,
                                      size_t neededSize) {
  assert(PackedArray::checkInvariants(old));

  auto const oldSize = old->m_size;
  auto const cmret   = computeCapAndMask(neededSize);
  auto const cap     = cmret.first;
  auto const mask    = cmret.second;
  auto const ad      = smartAllocArray(cap, mask);

  auto const shiftedSize = uint64_t{oldSize} << 32;
  ad->m_kindAndSize      = shiftedSize | MixedArray::kMixedKind << 24;
  ad->m_posAndCount      = static_cast<uint32_t>(old->m_pos);  // zero count
  ad->m_capAndUsed       = shiftedSize | cap;
  ad->m_maskAndLoad      = shiftedSize | mask;
  ad->m_nextKI           = oldSize;

  assert(ad->m_kind == ArrayData::kMixedKind);
  assert(ad->m_size == oldSize);
  assert(ad->m_pos == old->m_pos);
  assert(ad->m_count == 0);
  assert(ad->m_used == oldSize);
  assert(ad->m_cap == cap);
  assert(ad->m_tableMask = mask);
  assert(ad->m_hLoad == oldSize);
  assert(ad->m_nextKI == oldSize);
  // Can't checkInvariants yet, since we haven't populated the payload.
  return ad;
}
示例#2
0
ArrayInit::ArrayInit(size_t n, Map, CheckAllocation)
#ifdef DEBUG
  : m_addCount(0)
  , m_expectedCount(n)
#endif
{
  if (n > std::numeric_limits<int>::max()) {
    MM().forceOOM();
    check_request_surprise_unlikely();
  }
  auto const cmret = computeCapAndMask(n);
  auto const allocsz = computeAllocBytes(cmret.first, cmret.second);
  if (UNLIKELY(allocsz > kMaxSmartSize && MM().preAllocOOM(allocsz))) {
    check_request_surprise_unlikely();
  }
  m_data = MixedArray::MakeReserveMixed(n);
  m_data->setRefCount(0);
  check_request_surprise_unlikely();
}