When requesting a large block of memory, newNumBlocks can be very large and time-consuming.
Signed-off-by: Haoyang Chen chenhaoyang@uniontech.com --- dlls/ole32/storage32.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c index 980b6c8d9f6..1bc8455cc6b 100644 --- a/dlls/ole32/storage32.c +++ b/dlls/ole32/storage32.c @@ -4144,7 +4144,7 @@ static void StorageImpl_SetNextBlockInChain( * */ static ULONG StorageImpl_GetNextFreeBigBlock( - StorageImpl* This) + StorageImpl* This, ULONG neededAddNumBlocks) { ULONG depotBlockIndexPos; BYTE depotBuffer[MAX_BIG_BLOCK_SIZE]; @@ -4269,7 +4269,7 @@ static ULONG StorageImpl_GetNextFreeBigBlock( /* * make sure that the block physically exists before using it */ - neededSize.QuadPart = StorageImpl_GetBigBlockOffset(This, freeBlock)+This->bigBlockSize; + neededSize.QuadPart = StorageImpl_GetBigBlockOffset(This, freeBlock)+This->bigBlockSize * neededAddNumBlocks;
ILockBytes_Stat(This->lockBytes, &statstg, STATFLAG_NONAME);
@@ -7403,7 +7403,7 @@ static BOOL BlockChainStream_Enlarge(BlockChainStream* This, */ if (blockIndex == BLOCK_END_OF_CHAIN) { - blockIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage); + blockIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage, 1); StorageImpl_SetNextBlockInChain(This->parentStorage, blockIndex, BLOCK_END_OF_CHAIN); @@ -7472,7 +7472,7 @@ static BOOL BlockChainStream_Enlarge(BlockChainStream* This, { while (oldNumBlocks < newNumBlocks) { - blockIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage); + blockIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage, newNumBlocks - oldNumBlocks);
StorageImpl_SetNextBlockInChain( This->parentStorage,
Signed-off-by: Esme Povirk esme@codeweavers.com In theory, if we want to minimize the number of calls to ILockBytes_SetSize, we should do the check based on 1 block, but set the size based on neededAddNumBlocks. But I'm not sure it's worth the added complexity to do that.