Hi,

        Ive added a couple of comments below. Its worth trying 
DOMNodeFilter. You could write one with the filtering criteria in it. I'm 
not sure how much faster it would be.


Gareth

> Needless to say, this is in-efficient.  My requests take quite a long time
> on a fast PC.  I am wondering if I either have bad search code(see below) or
> should I not store the data this way?  I have control over both.  It seems
> it would be faster to search if I changed the Patch element name to contain
> the RowIndex and ColIndex, such as Patch_Row#_Col#.

Sounds like it would be a bit faster to me as well.

> Code...
> DOMNode* CTarget::GetPatchNode(DOMNode* pSideNode, int iRowIndex, int
> iColIndex)
> {
>       DOMNodeList* pPatchNodeList =
> ((DOMElement*)pSideNode)->getElementsByTagNameNS(NULL, L"Patch");

This does a recursive search. Better to just iterate over the children of 
1 element if you know that the patch elements are all at one level.


>       if (pPatchNodeList)
>       {
>               int iNumPatchNodes = pPatchNodeList->getLength();
> 
>               for (XMLSize_t p=0; p<iNumPatchNodes; p++)
>               {
>                       DOMNode* pPatchNode = pPatchNodeList->item(p);
>                       if (pPatchNode)
>                       {
>                               bool bRowFound = false;
>                               bool bColFound = false;
> 
>                               DOMNamedNodeMap* pDOMNamedNodeMap = 
>pPatchNode->getAttributes();
> 
>                               int iNumAttributes = pDOMNamedNodeMap->getLength();
> 
>                               for (XMLSize_t a=0; a<iNumAttributes; a++)
>                               {
>                                       DOMNode* pDOMNode = pDOMNamedNodeMap->item(a);
>                                       if (pDOMNode)
>                                       {
>                                               const XMLCh* pwszNodeName = 
>pDOMNode->getNodeName();


Could you enforce the attributes exist with a DTD? If so then you could 
speed this up by just checking the first letter of the first attribute. If 
you only have one attribute then you could forgo this check. It follows 
that you could rewrite this to eliminate the getLength call.

> 
>                                               if (wcscmp(L"ColIndex", pwszNodeName) 
>== 0)
>                                               {
>                                                       const XMLCh* wszNodeValue = 
>pDOMNode->getNodeValue();
>                                                       ASSERT(wszNodeValue);
> 
>                                                       if (_ttoi(wszNodeValue) == 
>iColIndex)
>                                                               bColFound = true;
>                                                       else
>                                                               break;
>                                               }
> 
>                                               if (wcscmp(L"RowIndex", pwszNodeName) 
>== 0)
>                                               {
>                                                       const XMLCh* wszNodeValue = 
>pDOMNode->getNodeValue();
>                                                       ASSERT(wszNodeValue);
> 
>                                                       if (_ttoi(wszNodeValue) == 
>iRowIndex)
>                                                               bRowFound = true;
>                                                       else
>                                                               break;
>                                               }
> 
>                                               if (bRowFound && bColFound)
>                                                       return pPatchNode;
>                                       }
>                               }
>                       }
>               }
>       }
> 
>       return NULL;
> }
> 

Gareth

-- 
Gareth Reakes, Head of Product Development  
DecisionSoft Ltd.            http://www.decisionsoft.com
Office: +44 (0) 1865 203192



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to