Skip to content

Replace `QList` with `QVarLengthArray` for returning file indices from `calcChunkPos`

QList is inefficient for storing Uint32 file indices on 64-bit targets, since QList uses pointer-sized storage for storing small movable elements, i.e. double the size of Uint32. Additionally, QList dynamically allocates storage on heap, even if there are a few elements in the container.

Replace it with QVarLengthArray, with static storage for a small number of elements. The container will dynamically allocate storage if the number of elements exceed the static storage, but it will still be more efficient in terms of allocation size.

Additionally, add a limit of the max number of file indices to return from calcChunkPos. This is useful when the caller is not interested in all files contained in a chunk. This is the case for MultiFileCache::createPiece, which only needs to know whether there is only one or multiple files in a chunk. This function is called often, so the optimization may be worth the small complexity of the added check.

Merge request reports

Loading