gpt4 book ai didi

c++ - 使用 Xerces C++ 计算/访问 DOMNode 子节点的最快方法

转载 作者:太空宇宙 更新时间:2023-11-04 14:15:30 25 4
gpt4 key购买 nike

我正在尝试找出计算 Xerces C++ DOMNode 对象的子元素数量的最快方法,因为我正在尝试优化使用 Xerces 2.6 DOMParser 的 Windows 应用程序的性能。

似乎大部分时间都花在了计数和访问 child 上。我们的应用程序需要迭代文档中的每个节点以使用 DOMNode::setUserData() 将数据附加到它,我们最初使用 DOMNode::getChildNodes()DOMNodeList::getLength()DOMNodeList::item(int index) 来计算和访问 child ,但这些都是相对昂贵的操作。

当我们使用不同的调用习惯时,观察到了很大的性能提升DOMNode::getFirstChild() 获取第一个子节点并调用 DOMNode::getNextSibling() 以访问特定索引处的子节点或计算兄弟节点的数量获得总子节点数的第一个子元素。

但是,getNextSibling() 仍然是我们解析步骤中的瓶颈,所以我想知道是否有一种使用 Xerces 来遍历和访问子元素的速度更快的方法。

最佳答案

Yes soon after I posted, I added code to store and manage the child count for each node, and this has made a big difference. The same nodes were being visited repeatedly and the child count was being recalculated every time. This is quite an expensive operation as Xerces essentially rebuilds the DOM structure for that node to guarantee its liveness. We have our own object which encapsulates a Xerces DOMNode along with extra info that we need , and we use DOMNode::setUserData to associate our object with the relevant DOMnode, and that now seems to be the last remaining bottleneck.

关于c++ - 使用 Xerces C++ 计算/访问 DOMNode 子节点的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11543130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com