Qt QDomElement性能问题
Qt QDomElement performance issue
我正在编写一个用于处理GPX文件的应用程序,在使用QDomElement类读取大型XML文档时遇到了性能问题。带有包含数千个路点的GPS路径的文件可能需要半分钟才能加载。
这是我读取路径(路线或轨道)的代码:
void GPXPath::readXml(QDomElement &pathElement)
{
for (int i = 0; i < pathElement.childNodes().count(); ++i)
{
QDomElement child = pathElement.childNodes().item(i).toElement();
if (child.nodeName() == "trkpt" ||
child.nodeName() == "rtept")
{
GPXWaypoint wpt;
wpt.readXml(child);
waypoints_.append(wpt);
}
}
}
在用苹果仪器分析代码时,我注意到QDomNodeListPrivate::createList()负责大部分计算时间,它被QDomNodeList::count()和QDomNodeList::item()调用。
这似乎不是迭代QDomElement的子元素的有效方式,因为列表似乎是为每个操作重新生成的。我应该使用什么方法?
我尝试了这个
void GPXPath::readXml(QDomElement &pathElement)
{
QDomElement child = pathElement.firstChildElement();
while (!child.isNull())
{
if (child.nodeName() == "trkpt" ||
child.nodeName() == "rtept")
{
GPXWaypoint wpt;
wpt.readXml(child);
waypoints_.append(wpt);
}
child = child.nextSiblingElement();
}
}
事实证明,它的速度快了15倍。通过使用SAX,我可能可以更快地完成这项工作,但现在就可以了。
您应该考虑使用QT SAX而不是DOM。SAX解析器通常不会将整个XML文档加载到内存中,并且在
相关文章:
- 在类中使用随机生成器时出现性能问题
- Qt OpenGL 渲染到纹理性能问题
- 剪辑性能问题
- 使用双包装器类进行位操作(C++、clang)修复性能下降问题
- OpenCV - 基本操作 - 性能问题 [模式:发布]
- 使用 #define 进行跟踪日志记录以避免性能问题
- 在 Qt C++ 中在自定义项委托上绘制文本时的性能问题
- std::函数有性能问题,如何避免?
- 使用 const double* const 作为模板参数 - 代码性能问题
- 在C 中读取大型CSV文件性能问题
- MPI 二进制文件 I/O 基本功能和性能问题
- 如何修复macOS线程互斥锁性能缓慢的问题?
- 使用STD :: MAP在数据及其性能问题中查找重复项.我可以预先分配吗?
- C 功能性能问题
- 一维数组映射方式的性能差异问题
- 在C 性能问题中使用Getter返回地图
- 初始化每个班级成员时的性能问题
- 事件(开始,结束),1天的最大事件.C++ 中的性能问题
- 在X64模式下从C /CLI调用MASM PROC会产生意外的性能问题
- OpenGL:MESA3D屏幕上的软件渲染性能问题