nsresult
nsAttrAndChildArray::MakeMappedUnique(nsMappedAttributes* aAttributes)
{
  NS_ASSERTION(aAttributes, "missing attributes");

  if (!mImpl && !GrowBy(1)) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  if (!aAttributes->GetStyleSheet()) {
    // This doesn't currently happen, but it could if we do loading right

    nsRefPtr<nsMappedAttributes> mapped(aAttributes);
    mapped.swap(mImpl->mMappedAttrs);

    return NS_OK;
  }

  nsRefPtr<nsMappedAttributes> mapped =
    aAttributes->GetStyleSheet()->UniqueMappedAttributes(aAttributes);
  NS_ENSURE_TRUE(mapped, NS_ERROR_OUT_OF_MEMORY);

  if (mapped != aAttributes) {
    // Reset the stylesheet of aAttributes so that it doesn't spend time
    // trying to remove itself from the hash. There is no risk that aAttributes
    // is in the hash since it will always have come from GetModifiableMapped,
    // which never returns maps that are in the hash (such hashes are by
    // nature not modifiable).
    aAttributes->DropStyleSheetReference();
  }
  mapped.swap(mImpl->mMappedAttrs);

  return NS_OK;
}
//! Test concurrent invocations of method concurrent_vector::grow_by
void TestConcurrentGrowBy( int nthread ) {
    int m = 100000;
    MyVector v;
    tbb::parallel_for( tbb::blocked_range<int>(0,m,1000), GrowBy(v) );
    ASSERT( v.size()==size_t(m), NULL );

    // Verify that v is a permutation of 0..m
    int inversions = 0;
    bool* found = new bool[m];
    memset( found, 0, m );
    for( int i=0; i<m; ++i ) {
        int index = v[i].bar();
        ASSERT( !found[index], NULL );
        found[index] = true;
        if( i>0 )
            inversions += v[i].bar()<v[i-1].bar();
    }
    for( int i=0; i<m; ++i ) {
        ASSERT( found[i], NULL );
        ASSERT( nthread>1 || v[i].bar()==i, "sequential execution is wrong" );
    }
    delete[] found;
    if( nthread>1 && inversions<m/10 )
        std::printf("Warning: not much concurrency in TestConcurrentGrowBy\n");
}
Exemplo n.º 3
0
bool Value_Raw::put_Allocated( vuint32 inSize ) 
{
	vuint32 ByteSize = get_Allocated();

	if( inSize == ByteSize )
	{
		// Already allocated
		return true;
	}
	else if( inSize < ByteSize )
	{
		if( TruncateTo(inSize) != inSize )
		{
			return false;
		}
	}
	else
	{
		if( GrowBy(inSize - ByteSize) != inSize )
		{
			return false;
		}
	}

	return true;
}
Exemplo n.º 4
0
NMErr
TPointerArray::InsertItem(void* theItem, NMUInt32 ndx)
{
	if (ndx > fNumberOfItems)
	{
		ndx = fNumberOfItems;
	}
	
	NMErr theErr = GrowBy(1);
	
	if (theErr == kNMNoError)	// room available
	{
		NMUInt32 numToMove = fNumberOfItems - ndx;

		if (numToMove > 0)
		{
			machine_move_data((void*) &fItemArray[ndx], (void*) &fItemArray[ndx+1], numToMove * sizeof(void*));
		}

		fItemArray[ndx] = theItem;
		fNumberOfItems++;
	}

	return theErr;
}
nsresult
nsAttrAndChildArray::InsertChildAt(nsIContent* aChild, PRUint32 aPos)
{
  NS_ASSERTION(aChild, "nullchild");
  NS_ASSERTION(aPos <= ChildCount(), "out-of-bounds");

  PRUint32 offset = AttrSlotsSize();
  PRUint32 childCount = ChildCount();

  NS_ENSURE_TRUE(childCount < ATTRCHILD_ARRAY_MAX_CHILD_COUNT,
                 NS_ERROR_FAILURE);

  // First try to fit new child in existing childlist
  if (mImpl && offset + childCount < mImpl->mBufferSize) {
    void** pos = mImpl->mBuffer + offset + aPos;
    if (childCount != aPos) {
      memmove(pos + 1, pos, (childCount - aPos) * sizeof(nsIContent*));
    }
    SetChildAtPos(pos, aChild, aPos, childCount);

    SetChildCount(childCount + 1);

    return NS_OK;
  }

  // Try to fit new child in existing buffer by compressing attrslots
  if (offset && !mImpl->mBuffer[offset - ATTRSIZE]) {
    // Compress away all empty slots while we're at it. This might not be the
    // optimal thing to do.
    PRUint32 attrCount = NonMappedAttrCount();
    void** newStart = mImpl->mBuffer + attrCount * ATTRSIZE;
    void** oldStart = mImpl->mBuffer + offset;
    memmove(newStart, oldStart, aPos * sizeof(nsIContent*));
    memmove(&newStart[aPos + 1], &oldStart[aPos],
            (childCount - aPos) * sizeof(nsIContent*));
    SetChildAtPos(newStart + aPos, aChild, aPos, childCount);

    SetAttrSlotAndChildCount(attrCount, childCount + 1);

    return NS_OK;
  }

  // We can't fit in current buffer, Realloc time!
  if (!GrowBy(1)) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  void** pos = mImpl->mBuffer + offset + aPos;
  if (childCount != aPos) {
    memmove(pos + 1, pos, (childCount - aPos) * sizeof(nsIContent*));
  }
  SetChildAtPos(pos, aChild, aPos, childCount);

  SetChildCount(childCount + 1);
  
  return NS_OK;
}
Exemplo n.º 6
0
NMErr
TPointerArray::AddItem(void* theItem)
{
NMErr	theErr = GrowBy(1);
	
	if (theErr == kNMNoError)
	{
		fItemArray[fNumberOfItems] = theItem;
		fNumberOfItems++;
	}

	return theErr;
}
bool
nsAttrAndChildArray::AddAttrSlot()
{
  PRUint32 slotCount = AttrSlotCount();
  PRUint32 childCount = ChildCount();

  // Grow buffer if needed
  if (!(mImpl && mImpl->mBufferSize >= (slotCount + 1) * ATTRSIZE + childCount) &&
      !GrowBy(ATTRSIZE)) {
    return false;
  }
  void** offset = mImpl->mBuffer + slotCount * ATTRSIZE;

  if (childCount > 0) {
    memmove(&ATTRS(mImpl)[slotCount + 1], &ATTRS(mImpl)[slotCount],
            childCount * sizeof(nsIContent*));
  }

  SetAttrSlotCount(slotCount + 1);
  offset[0] = nsnull;
  offset[1] = nsnull;

  return true;
}
Exemplo n.º 8
0
bool Intersect(Rect2 rect1, Rect2 rect2)
{
	Rect2 collision_rect = GrowBy(rect1, rect2);
	return Contains(collision_rect, GetCenter(rect2));
}