uint QFragmentMapData::createFragment() { Q_ASSERT(head->freelist <= head->allocated); uint freePos = head->freelist; if (freePos == head->allocated) { // need to create some free space uint needed = qAllocMore((freePos+1)*fragmentSize, 0); Q_ASSERT(needed/fragmentSize > head->allocated); fragments = (char *)realloc(fragments, needed); head->allocated = needed/fragmentSize; F(freePos).right = 0; #ifndef QT_NO_DEBUG for (uint i = freePos; i < head->allocated; ++i) F(i).parent = 0xdeadbeef; #endif } uint nextPos = F(freePos).right; if (!nextPos) { nextPos = freePos+1; if (nextPos < head->allocated) F(nextPos).right = 0; } head->freelist = nextPos; #ifndef QT_NO_DEBUG Q_ASSERT(F(freePos).parent == 0xdeadbeef); F(freePos).parent = 0; if (nextPos < head->allocated) { Q_ASSERT(F(nextPos).parent == 0xdeadbeef); } #endif ++head->node_count; PMDEBUG("===> createFragment at %d", freePos); return freePos; }
static int grow(int size) { // dear compiler: don't optimize me out. volatile int x = qAllocMore(size * sizeof(void *), QListData::DataHeaderSize) / sizeof(void *); return x; }
int QVectorData::grow(int sizeofTypedData, int size, int sizeofT, bool excessive) { if (excessive) return size + size / 2; return qAllocMore(size * sizeofT, sizeofTypedData - sizeofT) / sizeofT; }