Commit 5d550cdc authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

ole32: Further simplify adjustPropertyChain and fold in findPlaceholder.

The logic is unchanged from the original version.
parent a7e69339
...@@ -169,12 +169,6 @@ static HRESULT deleteStreamProperty( ...@@ -169,12 +169,6 @@ static HRESULT deleteStreamProperty(
ULONG foundPropertyIndexToDelete, ULONG foundPropertyIndexToDelete,
StgProperty propertyToDelete); StgProperty propertyToDelete);
static HRESULT findPlaceholder(
StorageImpl *storage,
ULONG propertyIndexToStore,
ULONG storagePropertyIndex,
INT typeOfRelation);
static HRESULT adjustPropertyChain( static HRESULT adjustPropertyChain(
StorageImpl *This, StorageImpl *This,
StgProperty propertyToDelete, StgProperty propertyToDelete,
...@@ -2025,92 +2019,22 @@ static HRESULT deleteStreamProperty( ...@@ -2025,92 +2019,22 @@ static HRESULT deleteStreamProperty(
return S_OK; return S_OK;
} }
/********************************************************************* static void setPropertyLink(StgProperty *property, ULONG relation, ULONG new_target)
*
* Internal Method
*
* Finds a placeholder for the StgProperty within the Storage
*
*/
static HRESULT findPlaceholder(
StorageImpl *storage,
ULONG propertyIndexToStore,
ULONG storePropertyIndex,
INT typeOfRelation)
{ {
StgProperty storeProperty; switch (relation)
BOOL res = TRUE;
/*
* Read the storage property
*/
res = StorageImpl_ReadProperty(
storage->base.ancestorStorage,
storePropertyIndex,
&storeProperty);
if(! res)
{
return E_FAIL;
}
if (typeOfRelation == PROPERTY_RELATION_PREVIOUS)
{
if (storeProperty.leftChild != PROPERTY_NULL)
{
return findPlaceholder(
storage,
propertyIndexToStore,
storeProperty.leftChild,
typeOfRelation);
}
else
{
storeProperty.leftChild = propertyIndexToStore;
}
}
else if (typeOfRelation == PROPERTY_RELATION_NEXT)
{
if (storeProperty.rightChild != PROPERTY_NULL)
{
return findPlaceholder(
storage,
propertyIndexToStore,
storeProperty.rightChild,
typeOfRelation);
}
else
{
storeProperty.rightChild = propertyIndexToStore;
}
}
else if (typeOfRelation == PROPERTY_RELATION_DIR)
{
if (storeProperty.dirProperty != PROPERTY_NULL)
{
return findPlaceholder(
storage,
propertyIndexToStore,
storeProperty.dirProperty,
typeOfRelation);
}
else
{
storeProperty.dirProperty = propertyIndexToStore;
}
}
res = StorageImpl_WriteProperty(
storage->base.ancestorStorage,
storePropertyIndex,
&storeProperty);
if(!res)
{ {
return E_FAIL; case PROPERTY_RELATION_PREVIOUS:
property->leftChild = new_target;
break;
case PROPERTY_RELATION_NEXT:
property->rightChild = new_target;
break;
case PROPERTY_RELATION_DIR:
property->dirProperty = new_target;
break;
default:
assert(0);
} }
return S_OK;
} }
/************************************************************************* /*************************************************************************
...@@ -2127,11 +2051,6 @@ static HRESULT adjustPropertyChain( ...@@ -2127,11 +2051,6 @@ static HRESULT adjustPropertyChain(
ULONG parentPropertyId, ULONG parentPropertyId,
INT typeOfRelation) INT typeOfRelation)
{ {
ULONG newLinkProperty = PROPERTY_NULL;
BOOL needToFindAPlaceholder = FALSE;
ULONG storeNode = PROPERTY_NULL;
ULONG toStoreNode = PROPERTY_NULL;
INT relationType = 0;
HRESULT hr = S_OK; HRESULT hr = S_OK;
BOOL res = TRUE; BOOL res = TRUE;
...@@ -2140,64 +2059,69 @@ static HRESULT adjustPropertyChain( ...@@ -2140,64 +2059,69 @@ static HRESULT adjustPropertyChain(
/* /*
* Replace the deleted entry with its left child * Replace the deleted entry with its left child
*/ */
newLinkProperty = propertyToDelete.leftChild; setPropertyLink(&parentProperty, typeOfRelation, propertyToDelete.leftChild);
res = StorageImpl_WriteProperty(
This->base.ancestorStorage,
parentPropertyId,
&parentProperty);
if(!res)
{
return E_FAIL;
}
if (propertyToDelete.rightChild != PROPERTY_NULL) if (propertyToDelete.rightChild != PROPERTY_NULL)
{ {
/* /*
* We also need to find a place for the other link, setup variables * We need to reinsert the right child somewhere. We already know it and
* to do this at the end... * its children are greater than everything in the left tree, so we
* insert it at the rightmost point in the left tree.
*/ */
needToFindAPlaceholder = TRUE; ULONG newRightChildParent = propertyToDelete.leftChild;
storeNode = propertyToDelete.leftChild; StgProperty newRightChildParentProperty;
toStoreNode = propertyToDelete.rightChild;
relationType = PROPERTY_RELATION_NEXT; do
{
res = StorageImpl_ReadProperty(
This->base.ancestorStorage,
newRightChildParent,
&newRightChildParentProperty);
if (!res)
{
return E_FAIL;
}
if (newRightChildParentProperty.rightChild != PROPERTY_NULL)
newRightChildParent = newRightChildParentProperty.rightChild;
} while (newRightChildParentProperty.rightChild != PROPERTY_NULL);
newRightChildParentProperty.rightChild = propertyToDelete.rightChild;
res = StorageImpl_WriteProperty(
This->base.ancestorStorage,
newRightChildParent,
&newRightChildParentProperty);
if (!res)
{
return E_FAIL;
}
} }
} }
else if (propertyToDelete.rightChild != PROPERTY_NULL) else
{ {
/* /*
* Replace the deleted entry with its right child * Replace the deleted entry with its right child
*/ */
newLinkProperty = propertyToDelete.rightChild; setPropertyLink(&parentProperty, typeOfRelation, propertyToDelete.rightChild);
}
if (typeOfRelation == PROPERTY_RELATION_PREVIOUS) res = StorageImpl_WriteProperty(
{ This->base.ancestorStorage,
parentProperty.leftChild = newLinkProperty; parentPropertyId,
} &parentProperty);
else if (typeOfRelation == PROPERTY_RELATION_NEXT) if(!res)
{ {
parentProperty.rightChild = newLinkProperty; return E_FAIL;
} }
else /* (typeOfRelation == PROPERTY_RELATION_DIR) */
{
parentProperty.dirProperty = newLinkProperty;
}
/*
* Write back the parent property
*/
res = StorageImpl_WriteProperty(
This->base.ancestorStorage,
parentPropertyId,
&parentProperty);
if(! res)
{
return E_FAIL;
}
/*
* If a placeholder is required for the other link, then, find one and
* get out of here...
*/
if (needToFindAPlaceholder)
{
hr = findPlaceholder(
This,
toStoreNode,
storeNode,
relationType);
} }
return hr; return hr;
......
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