Commit 0445eb8b authored by Thuy Nguyen's avatar Thuy Nguyen Committed by Alexandre Julliard

Smarter way of searching for a free block.

parent c08b9c5b
...@@ -1921,6 +1921,11 @@ HRESULT StorageImpl_Construct( ...@@ -1921,6 +1921,11 @@ HRESULT StorageImpl_Construct(
* There is no block depot cached yet. * There is no block depot cached yet.
*/ */
This->indexBlockDepotCached = 0xFFFFFFFF; This->indexBlockDepotCached = 0xFFFFFFFF;
/*
* Start searching for free blocks with block 0.
*/
This->prevFreeBlock = 0;
/* /*
* Create the block chain abstractions. * Create the block chain abstractions.
...@@ -2026,7 +2031,10 @@ ULONG StorageImpl_GetNextFreeBigBlock( ...@@ -2026,7 +2031,10 @@ ULONG StorageImpl_GetNextFreeBigBlock(
ULONG blocksPerDepot = This->bigBlockSize / sizeof(ULONG); ULONG blocksPerDepot = This->bigBlockSize / sizeof(ULONG);
ULONG nextBlockIndex = BLOCK_SPECIAL; ULONG nextBlockIndex = BLOCK_SPECIAL;
int depotIndex = 0; int depotIndex = 0;
ULONG blockNoInSequence = 0; ULONG freeBlock = BLOCK_UNUSED;
depotIndex = This->prevFreeBlock / blocksPerDepot;
depotBlockOffset = (This->prevFreeBlock % blocksPerDepot) * sizeof(ULONG);
/* /*
* Scan the entire big block depot until we find a block marked free * Scan the entire big block depot until we find a block marked free
...@@ -2115,15 +2123,16 @@ ULONG StorageImpl_GetNextFreeBigBlock( ...@@ -2115,15 +2123,16 @@ ULONG StorageImpl_GetNextFreeBigBlock(
if (depotBuffer != 0) if (depotBuffer != 0)
{ {
depotBlockOffset = 0;
while ( ( (depotBlockOffset/sizeof(ULONG) ) < blocksPerDepot) && while ( ( (depotBlockOffset/sizeof(ULONG) ) < blocksPerDepot) &&
( nextBlockIndex != BLOCK_UNUSED)) ( nextBlockIndex != BLOCK_UNUSED))
{ {
StorageUtl_ReadDWord(depotBuffer, depotBlockOffset, &nextBlockIndex); StorageUtl_ReadDWord(depotBuffer, depotBlockOffset, &nextBlockIndex);
if (nextBlockIndex != BLOCK_UNUSED) if (nextBlockIndex == BLOCK_UNUSED)
blockNoInSequence++; {
freeBlock = (depotIndex * blocksPerDepot) +
(depotBlockOffset/sizeof(ULONG));
}
depotBlockOffset += sizeof(ULONG); depotBlockOffset += sizeof(ULONG);
} }
...@@ -2132,9 +2141,12 @@ ULONG StorageImpl_GetNextFreeBigBlock( ...@@ -2132,9 +2141,12 @@ ULONG StorageImpl_GetNextFreeBigBlock(
} }
depotIndex++; depotIndex++;
depotBlockOffset = 0;
} }
return blockNoInSequence; This->prevFreeBlock = freeBlock;
return freeBlock;
} }
/****************************************************************************** /******************************************************************************
...@@ -2309,6 +2321,9 @@ void StorageImpl_FreeBigBlock( ...@@ -2309,6 +2321,9 @@ void StorageImpl_FreeBigBlock(
ULONG blockIndex) ULONG blockIndex)
{ {
StorageImpl_SetNextBlockInChain(This, blockIndex, BLOCK_UNUSED); StorageImpl_SetNextBlockInChain(This, blockIndex, BLOCK_UNUSED);
if (blockIndex < This->prevFreeBlock)
This->prevFreeBlock = blockIndex;
} }
/************************************************************************ /************************************************************************
......
...@@ -298,6 +298,7 @@ struct StorageImpl ...@@ -298,6 +298,7 @@ struct StorageImpl
ULONG blockDepotCached[NUM_BLOCKS_PER_DEPOT_BLOCK]; ULONG blockDepotCached[NUM_BLOCKS_PER_DEPOT_BLOCK];
ULONG indexBlockDepotCached; ULONG indexBlockDepotCached;
ULONG prevFreeBlock;
/* /*
* Abstraction of the big block chains for the chains of the header. * Abstraction of the big block chains for the chains of the header.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment