Commit 454ed9f0 authored by Thuy Nguyen's avatar Thuy Nguyen Committed by Alexandre Julliard

Improved performance.

parent 0d5fe583
...@@ -2461,6 +2461,7 @@ void StorageImpl_SetNextBlockInChain( ...@@ -2461,6 +2461,7 @@ void StorageImpl_SetNextBlockInChain(
void* depotBuffer; void* depotBuffer;
assert(depotBlockCount < This->bigBlockDepotCount); assert(depotBlockCount < This->bigBlockDepotCount);
assert(blockIndex != nextBlock);
if (depotBlockCount < COUNT_BBDEPOTINHEADER) if (depotBlockCount < COUNT_BBDEPOTINHEADER)
{ {
...@@ -2713,7 +2714,7 @@ BOOL StorageImpl_ReadProperty( ...@@ -2713,7 +2714,7 @@ BOOL StorageImpl_ReadProperty(
ULARGE_INTEGER offsetInPropSet; ULARGE_INTEGER offsetInPropSet;
BOOL readSucessful; BOOL readSucessful;
ULONG bytesRead; ULONG bytesRead;
offsetInPropSet.HighPart = 0; offsetInPropSet.HighPart = 0;
offsetInPropSet.LowPart = index * PROPSET_BLOCK_SIZE; offsetInPropSet.LowPart = index * PROPSET_BLOCK_SIZE;
...@@ -3740,12 +3741,28 @@ BlockChainStream* BlockChainStream_Construct( ...@@ -3740,12 +3741,28 @@ BlockChainStream* BlockChainStream_Construct(
ULONG propertyIndex) ULONG propertyIndex)
{ {
BlockChainStream* newStream; BlockChainStream* newStream;
ULONG blockIndex;
newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(BlockChainStream)); newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(BlockChainStream));
newStream->parentStorage = parentStorage; newStream->parentStorage = parentStorage;
newStream->headOfStreamPlaceHolder = headOfStreamPlaceHolder; newStream->headOfStreamPlaceHolder = headOfStreamPlaceHolder;
newStream->ownerPropertyIndex = propertyIndex; newStream->ownerPropertyIndex = propertyIndex;
newStream->lastBlockNoInSequence = 0xFFFFFFFF;
newStream->tailIndex = BLOCK_END_OF_CHAIN;
newStream->numBlocks = 0;
blockIndex = BlockChainStream_GetHeadOfChain(newStream);
while (blockIndex != BLOCK_END_OF_CHAIN)
{
newStream->numBlocks++;
newStream->tailIndex = blockIndex;
blockIndex = StorageImpl_GetNextBlockInChain(
parentStorage,
blockIndex);
}
return newStream; return newStream;
} }
...@@ -3833,10 +3850,24 @@ BOOL BlockChainStream_ReadAt(BlockChainStream* This, ...@@ -3833,10 +3850,24 @@ BOOL BlockChainStream_ReadAt(BlockChainStream* This,
BYTE* bufferWalker; BYTE* bufferWalker;
BYTE* bigBlockBuffer; BYTE* bigBlockBuffer;
if (This->lastBlockNoInSequence == 0xFFFFFFFF)
This->lastBlockNoInSequence = blockNoInSequence;
/* /*
* Find the first block in the stream that contains part of the buffer. * Find the first block in the stream that contains part of the buffer.
*/ */
blockIndex = BlockChainStream_GetHeadOfChain(This); if (blockNoInSequence > This->lastBlockNoInSequence)
{
ULONG temp = blockNoInSequence;
blockIndex = This->lastBlockNoInSequenceIndex;
blockNoInSequence -= This->lastBlockNoInSequence;
This->lastBlockNoInSequence = temp;
}
else
{
blockIndex = BlockChainStream_GetHeadOfChain(This);
This->lastBlockNoInSequence = blockNoInSequence;
}
while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN)) while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN))
{ {
...@@ -3846,6 +3877,8 @@ BOOL BlockChainStream_ReadAt(BlockChainStream* This, ...@@ -3846,6 +3877,8 @@ BOOL BlockChainStream_ReadAt(BlockChainStream* This,
blockNoInSequence--; blockNoInSequence--;
} }
This->lastBlockNoInSequenceIndex = blockIndex;
/* /*
* Start reading the buffer. * Start reading the buffer.
*/ */
...@@ -3906,11 +3939,26 @@ BOOL BlockChainStream_WriteAt(BlockChainStream* This, ...@@ -3906,11 +3939,26 @@ BOOL BlockChainStream_WriteAt(BlockChainStream* This,
BYTE* bufferWalker; BYTE* bufferWalker;
BYTE* bigBlockBuffer; BYTE* bigBlockBuffer;
if (This->lastBlockNoInSequence == 0xFFFFFFFF)
This->lastBlockNoInSequence = blockNoInSequence;
/* /*
* Find the first block in the stream that contains part of the buffer. * Find the first block in the stream that contains part of the buffer.
*/ */
blockIndex = BlockChainStream_GetHeadOfChain(This); if (blockNoInSequence > This->lastBlockNoInSequence)
{
ULONG temp = blockNoInSequence;
blockIndex = This->lastBlockNoInSequenceIndex;
blockNoInSequence -= This->lastBlockNoInSequence;
This->lastBlockNoInSequence = temp;
}
else
{
blockIndex = BlockChainStream_GetHeadOfChain(This);
This->lastBlockNoInSequence = blockNoInSequence;
}
while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN)) while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN))
{ {
blockIndex = blockIndex =
...@@ -3919,6 +3967,8 @@ BOOL BlockChainStream_WriteAt(BlockChainStream* This, ...@@ -3919,6 +3967,8 @@ BOOL BlockChainStream_WriteAt(BlockChainStream* This,
blockNoInSequence--; blockNoInSequence--;
} }
This->lastBlockNoInSequenceIndex = blockIndex;
/* /*
* Here, I'm casting away the constness on the buffer variable * Here, I'm casting away the constness on the buffer variable
* This is OK since we don't intend to modify that buffer. * This is OK since we don't intend to modify that buffer.
...@@ -4001,6 +4051,9 @@ BOOL BlockChainStream_Shrink(BlockChainStream* This, ...@@ -4001,6 +4051,9 @@ BOOL BlockChainStream_Shrink(BlockChainStream* This,
blockIndex, blockIndex,
BLOCK_END_OF_CHAIN); BLOCK_END_OF_CHAIN);
This->tailIndex = blockIndex;
This->numBlocks = numBlocks;
/* /*
* Mark the extra blocks as free * Mark the extra blocks as free
*/ */
...@@ -4046,24 +4099,25 @@ BOOL BlockChainStream_Enlarge(BlockChainStream* This, ...@@ -4046,24 +4099,25 @@ BOOL BlockChainStream_Enlarge(BlockChainStream* This,
} }
else else
{ {
StgProperty chainProp; StgProperty chainProp;
assert(This->ownerPropertyIndex != PROPERTY_NULL); assert(This->ownerPropertyIndex != PROPERTY_NULL);
StorageImpl_ReadProperty( StorageImpl_ReadProperty(
This->parentStorage, This->parentStorage,
This->ownerPropertyIndex, This->ownerPropertyIndex,
&chainProp); &chainProp);
chainProp.startingBlock = blockIndex; chainProp.startingBlock = blockIndex;
StorageImpl_WriteProperty( StorageImpl_WriteProperty(
This->parentStorage, This->parentStorage,
This->ownerPropertyIndex, This->ownerPropertyIndex,
&chainProp); &chainProp);
} }
}
currentBlock = blockIndex; This->tailIndex = blockIndex;
This->numBlocks = 1;
}
/* /*
* Figure out how many blocks are needed to contain this stream * Figure out how many blocks are needed to contain this stream
...@@ -4076,15 +4130,25 @@ BOOL BlockChainStream_Enlarge(BlockChainStream* This, ...@@ -4076,15 +4130,25 @@ BOOL BlockChainStream_Enlarge(BlockChainStream* This,
/* /*
* Go to the current end of chain * Go to the current end of chain
*/ */
while (blockIndex != BLOCK_END_OF_CHAIN) if (This->tailIndex == BLOCK_END_OF_CHAIN)
{ {
oldNumBlocks++;
currentBlock = blockIndex; currentBlock = blockIndex;
blockIndex = while (blockIndex != BLOCK_END_OF_CHAIN)
StorageImpl_GetNextBlockInChain(This->parentStorage, currentBlock); {
This->numBlocks++;
currentBlock = blockIndex;
blockIndex =
StorageImpl_GetNextBlockInChain(This->parentStorage, currentBlock);
}
This->tailIndex = currentBlock;
} }
currentBlock = This->tailIndex;
oldNumBlocks = This->numBlocks;
/* /*
* Add new blocks to the chain * Add new blocks to the chain
*/ */
...@@ -4106,6 +4170,9 @@ BOOL BlockChainStream_Enlarge(BlockChainStream* This, ...@@ -4106,6 +4170,9 @@ BOOL BlockChainStream_Enlarge(BlockChainStream* This,
oldNumBlocks++; oldNumBlocks++;
} }
This->tailIndex = blockIndex;
This->numBlocks = newNumBlocks;
return TRUE; return TRUE;
} }
......
...@@ -140,8 +140,7 @@ struct BigBlockFile ...@@ -140,8 +140,7 @@ struct BigBlockFile
HANDLE hfile; HANDLE hfile;
HANDLE hfilemap; HANDLE hfilemap;
DWORD flProtect; DWORD flProtect;
MappedPage *headmap_ro; MappedPage *maplisthead;
MappedPage *headmap_w;
BigBlock *headblock; BigBlock *headblock;
}; };
...@@ -724,8 +723,12 @@ void StorageUtl_CopyPropertyToSTATSTG(STATSTG* destination, ...@@ -724,8 +723,12 @@ void StorageUtl_CopyPropertyToSTATSTG(STATSTG* destination,
struct BlockChainStream struct BlockChainStream
{ {
StorageImpl* parentStorage; StorageImpl* parentStorage;
ULONG* headOfStreamPlaceHolder; ULONG* headOfStreamPlaceHolder;
ULONG ownerPropertyIndex; ULONG ownerPropertyIndex;
ULONG lastBlockNoInSequence;
ULONG lastBlockNoInSequenceIndex;
ULONG tailIndex;
ULONG numBlocks;
}; };
/* /*
......
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