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