diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-02-10 12:17:35 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-02-13 15:36:06 +0000 |
commit | 32f6315d6d458600bb3f1db08c53148557382c21 (patch) | |
tree | adc107686a60692f4e53a7037b382dd5ce30095b /src | |
parent | 66b58804a3291890bd6ae8444911a6a22bf8c321 (diff) |
Make better use of the remaining memory before calling GC
Some slots still have free memory available. If we only
need to allocate a small object, check if we can split up
one of these slots before giving up and starting a GC
cycle.
Change-Id: I11fb9d53c607274dbb5fd0bc02088ed94bfe7c4e
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/memory/qv4mm.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp index ebd5abd763..1609dd5adb 100644 --- a/src/qml/memory/qv4mm.cpp +++ b/src/qml/memory/qv4mm.cpp @@ -475,7 +475,7 @@ HeapItem *BlockAllocator::allocate(size_t size, bool forceAllocation) { goto done; HeapItem *remainder = m + slotsRequired; - if (remainingSlots >= 2*NumBins) { + if (remainingSlots > nFree) { if (nFree) { size_t bin = binForSlots(nFree); nextFree->freeData.next = freeBins[bin]; @@ -495,6 +495,24 @@ HeapItem *BlockAllocator::allocate(size_t size, bool forceAllocation) { last = &m->freeData.next; } + if (slotsRequired < NumBins - 1) { + // check if we can split up another slot + for (size_t i = slotsRequired + 1; i < NumBins - 1; ++i) { + m = freeBins[i]; + if (m) { + freeBins[i] = m->freeData.next; // take it out of the list +// qDebug() << "got item" << slotsRequired << "from slot" << i; + size_t remainingSlots = i - slotsRequired; + Q_ASSERT(remainingSlots < NumBins - 1); + HeapItem *remainder = m + slotsRequired; + remainder->freeData.availableSlots = remainingSlots; + remainder->freeData.next = freeBins[remainingSlots]; + freeBins[remainingSlots] = remainder; + goto done; + } + } + } + if (!m) { if (!forceAllocation) return 0; |