summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-08-31 14:37:12 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-08-31 14:37:12 (GMT)
commit690fcf380985c5fefbb8531fbeb54a1432b49044 (patch)
treee37f85be39f1319c07abafb771553ad2d5e4967c
parent8b24749079ec9981c617f861cb7f3811e01d2cd2 (diff)
Use a string pool for sharing some string data on loading cache & osm/o5m
-rw-r--r--src/plugins/runner/cache/CacheRunner.cpp20
-rw-r--r--src/plugins/runner/osm/OsmParser.cpp26
2 files changed, 33 insertions, 13 deletions
diff --git a/src/plugins/runner/cache/CacheRunner.cpp b/src/plugins/runner/cache/CacheRunner.cpp
index a6edf35..0504ba7 100644
--- a/src/plugins/runner/cache/CacheRunner.cpp
+++ b/src/plugins/runner/cache/CacheRunner.cpp
@@ -16,6 +16,7 @@
#include <QFile>
#include <QDataStream>
+#include <QSet>
namespace Marble
{
@@ -81,28 +82,33 @@ GeoDataDocument* CacheRunner::parseFile( const QString &fileName, DocumentRole r
qint8 tmpint8;
qint16 tmpint16;
+ // share string data on the heap at least for this file
+ QSet<QString> stringPool;
+ const QString gmtId = QStringLiteral("gmt");
+ const QString dstId = QStringLiteral("dst");
+
while ( !in.atEnd() ) {
GeoDataPlacemark *mark = new GeoDataPlacemark;
- in >> tmpstr;
+ in >> tmpstr; tmpstr = *stringPool.insert(tmpstr);
mark->setName( tmpstr );
in >> lon >> lat >> alt;
mark->setCoordinate( (qreal)(lon), (qreal)(lat), (qreal)(alt) );
- in >> tmpstr;
+ in >> tmpstr; tmpstr = *stringPool.insert(tmpstr);
mark->setRole( tmpstr );
- in >> tmpstr;
+ in >> tmpstr; tmpstr = *stringPool.insert(tmpstr);
mark->setDescription( tmpstr );
- in >> tmpstr;
+ in >> tmpstr; tmpstr = *stringPool.insert(tmpstr);
mark->setCountryCode( tmpstr );
- in >> tmpstr;
+ in >> tmpstr; tmpstr = *stringPool.insert(tmpstr);
mark->setState( tmpstr );
in >> area;
mark->setArea( (qreal)(area) );
in >> tmpint64;
mark->setPopulation( tmpint64 );
in >> tmpint16;
- mark->extendedData().addValue( GeoDataData( "gmt", int( tmpint16 ) ) );
+ mark->extendedData().addValue(GeoDataData(gmtId, int(tmpint16)));
in >> tmpint8;
- mark->extendedData().addValue( GeoDataData( "dst", int( tmpint8 ) ) );
+ mark->extendedData().addValue(GeoDataData(dstId, int(tmpint8)));
document->append( mark );
}
diff --git a/src/plugins/runner/osm/OsmParser.cpp b/src/plugins/runner/osm/OsmParser.cpp
index 69a0311..58b6e33 100644
--- a/src/plugins/runner/osm/OsmParser.cpp
+++ b/src/plugins/runner/osm/OsmParser.cpp
@@ -25,6 +25,7 @@
#include <QFile>
#include <QFileInfo>
#include <QBuffer>
+#include <QSet>
namespace Marble {
@@ -44,6 +45,8 @@ GeoDataDocument* OsmParser::parseO5m(const QString &filename, QString &error)
O5mreaderDataset data;
O5mreaderIterateRet outerState, innerState;
char *key, *value;
+ // share string data on the heap at least for this file
+ QSet<QString> stringPool;
OsmNodes nodes;
OsmWays ways;
@@ -65,7 +68,9 @@ GeoDataDocument* OsmParser::parseO5m(const QString &filename, QString &error)
node.setCoordinates(GeoDataCoordinates(data.lon*1.0e-7, data.lat*1.0e-7,
0.0, GeoDataCoordinates::Degree));
while ((innerState = o5mreader_iterateTags(reader, &key, &value)) == O5MREADER_ITERATE_RET_NEXT) {
- node.osmData().addTag(key, value);
+ const QString keyString = *stringPool.insert(QString::fromUtf8(key));
+ const QString valueString = *stringPool.insert(QString::fromUtf8(value));
+ node.osmData().addTag(keyString, valueString);
}
}
break;
@@ -78,7 +83,9 @@ GeoDataDocument* OsmParser::parseO5m(const QString &filename, QString &error)
way.addReference(nodeId);
}
while ((innerState = o5mreader_iterateTags(reader, &key, &value)) == O5MREADER_ITERATE_RET_NEXT) {
- way.osmData().addTag(key, value);
+ const QString keyString = *stringPool.insert(QString::fromUtf8(key));
+ const QString valueString = *stringPool.insert(QString::fromUtf8(value));
+ way.osmData().addTag(keyString, valueString);
}
}
break;
@@ -90,10 +97,13 @@ GeoDataDocument* OsmParser::parseO5m(const QString &filename, QString &error)
uint8_t type;
uint64_t refId;
while ((innerState = o5mreader_iterateRefs(reader, &refId, &type, &role)) == O5MREADER_ITERATE_RET_NEXT) {
- relation.addMember(refId, role, relationTypes[type]);
+ const QString roleString = *stringPool.insert(QString::fromUtf8(role));
+ relation.addMember(refId, roleString, relationTypes[type]);
}
while ((innerState = o5mreader_iterateTags(reader, &key, &value)) == O5MREADER_ITERATE_RET_NEXT) {
- relation.osmData().addTag(key, value);
+ const QString keyString = *stringPool.insert(QString::fromUtf8(key));
+ const QString valueString = *stringPool.insert(QString::fromUtf8(value));
+ relation.osmData().addTag(keyString, valueString);
}
}
break;
@@ -135,6 +145,8 @@ GeoDataDocument* OsmParser::parseXml(const QString &filename, QString &error)
OsmPlacemarkData* osmData(0);
QString parentTag;
qint64 parentId(0);
+ // share string data on the heap at least for this file
+ QSet<QString> stringPool;
OsmNodes m_nodes;
OsmWays m_ways;
@@ -164,8 +176,10 @@ GeoDataDocument* OsmParser::parseXml(const QString &filename, QString &error)
osmData = &m_relations[parentId].osmData();
}
} else if (tagName == osm::osmTag_tag) {
- osmData->addTag(parser.attributes().value(QLatin1String("k")).toString(),
- parser.attributes().value(QLatin1String("v")).toString());
+ const QXmlStreamAttributes &attributes = parser.attributes();
+ const QString keyString = *stringPool.insert(attributes.value(QLatin1String("k")).toString());
+ const QString valueString = *stringPool.insert(attributes.value(QLatin1String("v")).toString());
+ osmData->addTag(keyString, valueString);
} else if (tagName == osm::osmTag_nd && parentTag == osm::osmTag_way) {
m_ways[parentId].addReference(parser.attributes().value(QLatin1String("ref")).toLongLong());
} else if (tagName == osm::osmTag_member && parentTag == osm::osmTag_relation) {