From 0445eb8b7ed32de0d96e246a654ae0a3a617e6a1 Mon Sep 17 00:00:00 2001 From: Thuy Nguyen Date: Tue, 9 Mar 1999 17:40:00 +0000 Subject: [PATCH] Smarter way of searching for a free block. --- ole/storage32.c | 27 +++++++++++++++++++++------ ole/storage32.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ole/storage32.c b/ole/storage32.c index fd812f474ad..bb2b6cc157c 100644 --- a/ole/storage32.c +++ b/ole/storage32.c @@ -1921,6 +1921,11 @@ HRESULT StorageImpl_Construct( * There is no block depot cached yet. */ This->indexBlockDepotCached = 0xFFFFFFFF; + + /* + * Start searching for free blocks with block 0. + */ + This->prevFreeBlock = 0; /* * Create the block chain abstractions. @@ -2026,7 +2031,10 @@ ULONG StorageImpl_GetNextFreeBigBlock( ULONG blocksPerDepot = This->bigBlockSize / sizeof(ULONG); ULONG nextBlockIndex = BLOCK_SPECIAL; 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 @@ -2115,15 +2123,16 @@ ULONG StorageImpl_GetNextFreeBigBlock( if (depotBuffer != 0) { - depotBlockOffset = 0; - while ( ( (depotBlockOffset/sizeof(ULONG) ) < blocksPerDepot) && ( nextBlockIndex != BLOCK_UNUSED)) { StorageUtl_ReadDWord(depotBuffer, depotBlockOffset, &nextBlockIndex); - if (nextBlockIndex != BLOCK_UNUSED) - blockNoInSequence++; + if (nextBlockIndex == BLOCK_UNUSED) + { + freeBlock = (depotIndex * blocksPerDepot) + + (depotBlockOffset/sizeof(ULONG)); + } depotBlockOffset += sizeof(ULONG); } @@ -2132,9 +2141,12 @@ ULONG StorageImpl_GetNextFreeBigBlock( } depotIndex++; + depotBlockOffset = 0; } - return blockNoInSequence; + This->prevFreeBlock = freeBlock; + + return freeBlock; } /****************************************************************************** @@ -2309,6 +2321,9 @@ void StorageImpl_FreeBigBlock( ULONG blockIndex) { StorageImpl_SetNextBlockInChain(This, blockIndex, BLOCK_UNUSED); + + if (blockIndex < This->prevFreeBlock) + This->prevFreeBlock = blockIndex; } /************************************************************************ diff --git a/ole/storage32.h b/ole/storage32.h index a60ad370812..ba4ff9061c1 100644 --- a/ole/storage32.h +++ b/ole/storage32.h @@ -298,6 +298,7 @@ struct StorageImpl ULONG blockDepotCached[NUM_BLOCKS_PER_DEPOT_BLOCK]; ULONG indexBlockDepotCached; + ULONG prevFreeBlock; /* * Abstraction of the big block chains for the chains of the header.