Browse Source

perf(MapEngine): avoid some unnecessary string copies

QGC4.4
leonardosimovic 2 years ago committed by Don Gagne
parent
commit
d0c61b2f79
  1. 12
      src/QtLocationPlugin/QGCMapEngine.cpp
  2. 16
      src/QtLocationPlugin/QGCMapEngine.h
  3. 2
      src/QtLocationPlugin/QGCMapEngineData.h
  4. 19
      src/QtLocationPlugin/QGCMapUrlEngine.cpp
  5. 14
      src/QtLocationPlugin/QGCMapUrlEngine.h
  6. 6
      src/QtLocationPlugin/QGCTileCacheWorker.cpp

12
src/QtLocationPlugin/QGCMapEngine.cpp

@ -200,7 +200,7 @@ QGCMapEngine::addTask(QGCMapTask* task)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
QGCMapEngine::cacheTile(QString type, int x, int y, int z, const QByteArray& image, const QString &format, qulonglong set) QGCMapEngine::cacheTile(const QString& type, int x, int y, int z, const QByteArray& image, const QString &format, qulonglong set)
{ {
QString hash = getTileHash(type, x, y, z); QString hash = getTileHash(type, x, y, z);
cacheTile(type, hash, image, format, set); cacheTile(type, hash, image, format, set);
@ -208,7 +208,7 @@ QGCMapEngine::cacheTile(QString type, int x, int y, int z, const QByteArray& ima
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
QGCMapEngine::cacheTile(QString type, const QString& hash, const QByteArray& image, const QString& format, qulonglong set) QGCMapEngine::cacheTile(const QString& type, const QString& hash, const QByteArray& image, const QString& format, qulonglong set)
{ {
AppSettings* appSettings = qgcApp()->toolbox()->settingsManager()->appSettings(); AppSettings* appSettings = qgcApp()->toolbox()->settingsManager()->appSettings();
//-- If we are allowed to persist data, save tile to cache //-- If we are allowed to persist data, save tile to cache
@ -220,7 +220,7 @@ QGCMapEngine::cacheTile(QString type, const QString& hash, const QByteArray& ima
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString QString
QGCMapEngine::getTileHash(QString type, int x, int y, int z) QGCMapEngine::getTileHash(const QString& type, int x, int y, int z)
{ {
return QString::asprintf("%010d%08d%08d%03d", getQGCMapEngine()->urlFactory()->getIdFromType(type), x, y, z); return QString::asprintf("%010d%08d%08d%03d", getQGCMapEngine()->urlFactory()->getIdFromType(type), x, y, z);
} }
@ -235,7 +235,7 @@ QGCMapEngine::hashToType(const QString& hash)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QGCFetchTileTask* QGCFetchTileTask*
QGCMapEngine::createFetchTileTask(QString type, int x, int y, int z) QGCMapEngine::createFetchTileTask(const QString& type, int x, int y, int z)
{ {
QString hash = getTileHash(type, x, y, z); QString hash = getTileHash(type, x, y, z);
QGCFetchTileTask* task = new QGCFetchTileTask(hash); QGCFetchTileTask* task = new QGCFetchTileTask(hash);
@ -244,7 +244,7 @@ QGCMapEngine::createFetchTileTask(QString type, int x, int y, int z)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QGCTileSet QGCTileSet
QGCMapEngine::getTileCount(int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, QString mapType) QGCMapEngine::getTileCount(int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, const QString& mapType)
{ {
if(zoom < 1) zoom = 1; if(zoom < 1) zoom = 1;
if(zoom > MAX_MAP_ZOOM) zoom = MAX_MAP_ZOOM; if(zoom > MAX_MAP_ZOOM) zoom = MAX_MAP_ZOOM;
@ -368,7 +368,7 @@ QGCMapEngine::_pruned()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int int
QGCMapEngine::concurrentDownloads(QString type) QGCMapEngine::concurrentDownloads(const QString& type)
{ {
Q_UNUSED(type); Q_UNUSED(type);
// TODO : We may want different values depending on // TODO : We may want different values depending on

16
src/QtLocationPlugin/QGCMapEngine.h

@ -36,13 +36,13 @@ public:
void init (); void init ();
void addTask (QGCMapTask *task); void addTask (QGCMapTask *task);
void cacheTile (QString type, int x, int y, int z, const QByteArray& image, const QString& format, qulonglong set = UINT64_MAX); void cacheTile (const QString& type, int x, int y, int z, const QByteArray& image, const QString& format, qulonglong set = UINT64_MAX);
void cacheTile (QString type, const QString& hash, const QByteArray& image, const QString& format, qulonglong set = UINT64_MAX); void cacheTile (const QString& type, const QString& hash, const QByteArray& image, const QString& format, qulonglong set = UINT64_MAX);
QGCFetchTileTask* createFetchTileTask (QString type, int x, int y, int z); QGCFetchTileTask* createFetchTileTask (const QString& type, int x, int y, int z);
QStringList getMapNameList (); QStringList getMapNameList ();
const QString userAgent () { return _userAgent; } const QString userAgent () { return _userAgent; }
void setUserAgent (const QString& ua) { _userAgent = ua; } void setUserAgent (const QString& ua) { _userAgent = ua; }
QString hashToType (const QString& hash); QString hashToType (const QString& hash);
quint32 getMaxDiskCache (); quint32 getMaxDiskCache ();
void setMaxDiskCache (quint32 size); void setMaxDiskCache (quint32 size);
quint32 getMaxMemCache (); quint32 getMaxMemCache ();
@ -56,13 +56,13 @@ public:
UrlFactory* urlFactory () { return _urlFactory; } UrlFactory* urlFactory () { return _urlFactory; }
//-- Tile Math //-- Tile Math
static QGCTileSet getTileCount (int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, QString mapType); static QGCTileSet getTileCount (int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, const QString& mapType);
static QString getTileHash (QString type, int x, int y, int z); static QString getTileHash (const QString& type, int x, int y, int z);
static QString getTypeFromName (const QString &name); static QString getTypeFromName (const QString& name);
static QString bigSizeToString (quint64 size); static QString bigSizeToString (quint64 size);
static QString storageFreeSizeToString(quint64 size_MB); static QString storageFreeSizeToString(quint64 size_MB);
static QString numberToString (quint64 number); static QString numberToString (quint64 number);
static int concurrentDownloads (QString type); static int concurrentDownloads (const QString& type);
private slots: private slots:
void _updateTotals (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize); void _updateTotals (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize);

2
src/QtLocationPlugin/QGCMapEngineData.h

@ -76,7 +76,7 @@ class QGCCacheTile : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
QGCCacheTile (const QString hash, const QByteArray img, const QString format, QString type, qulonglong set = UINT64_MAX) QGCCacheTile (const QString& hash, const QByteArray& img, const QString& format, const QString& type, qulonglong set = UINT64_MAX)
: _set(set) : _set(set)
, _hash(hash) , _hash(hash)
, _img(img) , _img(img)

19
src/QtLocationPlugin/QGCMapUrlEngine.cpp

@ -106,7 +106,7 @@ QString UrlFactory::getImageFormat(int id, const QByteArray& image) {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString UrlFactory::getImageFormat(QString type, const QByteArray& image) { QString UrlFactory::getImageFormat(const QString& type, const QByteArray& image) {
if (_providersTable.find(type) != _providersTable.end()) { if (_providersTable.find(type) != _providersTable.end()) {
return _providersTable[type]->getImageFormat(image); return _providersTable[type]->getImageFormat(image);
} else { } else {
@ -127,7 +127,7 @@ QNetworkRequest UrlFactory::getTileURL(int id, int x, int y, int zoom,
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QNetworkRequest UrlFactory::getTileURL(QString type, int x, int y, int zoom, QNetworkRequest UrlFactory::getTileURL(const QString& type, int x, int y, int zoom,
QNetworkAccessManager* networkManager) { QNetworkAccessManager* networkManager) {
if (_providersTable.find(type) != _providersTable.end()) { if (_providersTable.find(type) != _providersTable.end()) {
return _providersTable[type]->getTileURL(x, y, zoom, networkManager); return _providersTable[type]->getTileURL(x, y, zoom, networkManager);
@ -137,7 +137,7 @@ QNetworkRequest UrlFactory::getTileURL(QString type, int x, int y, int zoom,
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
quint32 UrlFactory::averageSizeForType(QString type) { quint32 UrlFactory::averageSizeForType(const QString& type) {
if (_providersTable.find(type) != _providersTable.end()) { if (_providersTable.find(type) != _providersTable.end()) {
return _providersTable[type]->getAverageSize(); return _providersTable[type]->getAverageSize();
} }
@ -177,21 +177,26 @@ MapProvider* UrlFactory::getMapProviderFromId(int id)
return nullptr; return nullptr;
} }
//-----------------------------------------------------------------------------
// Todo : qHash produce a uint bigger than max(int) // Todo : qHash produce a uint bigger than max(int)
// There is still a low probability for this to // There is still a low probability for this to
// generate similar hash for different types // generate similar hash for different types
int UrlFactory::getIdFromType(QString type) { return (int)(qHash(type)>>1); } int
UrlFactory::getIdFromType(const QString& type)
{
return (int)(qHash(type)>>1);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int int
UrlFactory::long2tileX(QString mapType, double lon, int z) UrlFactory::long2tileX(const QString& mapType, double lon, int z)
{ {
return _providersTable[mapType]->long2tileX(lon, z); return _providersTable[mapType]->long2tileX(lon, z);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int int
UrlFactory::lat2tileY(QString mapType, double lat, int z) UrlFactory::lat2tileY(const QString& mapType, double lat, int z)
{ {
return _providersTable[mapType]->lat2tileY(lat, z); return _providersTable[mapType]->lat2tileY(lat, z);
} }
@ -199,7 +204,7 @@ UrlFactory::lat2tileY(QString mapType, double lat, int z)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QGCTileSet QGCTileSet
UrlFactory::getTileCount(int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, QString mapType) UrlFactory::getTileCount(int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, const QString& mapType)
{ {
return _providersTable[mapType]->getTileCount(zoom, topleftLon, topleftLat, bottomRightLon, bottomRightLat); return _providersTable[mapType]->getTileCount(zoom, topleftLon, topleftLat, bottomRightLon, bottomRightLat);
} }

14
src/QtLocationPlugin/QGCMapUrlEngine.h

@ -33,26 +33,26 @@ public:
UrlFactory (); UrlFactory ();
~UrlFactory (); ~UrlFactory ();
QNetworkRequest getTileURL (QString type, int x, int y, int zoom, QNetworkAccessManager* networkManager); QNetworkRequest getTileURL (const QString& type, int x, int y, int zoom, QNetworkAccessManager* networkManager);
QNetworkRequest getTileURL (int id, int x, int y, int zoom, QNetworkAccessManager* networkManager); QNetworkRequest getTileURL (int id, int x, int y, int zoom, QNetworkAccessManager* networkManager);
QString getImageFormat (QString type, const QByteArray& image); QString getImageFormat (const QString& type, const QByteArray& image);
QString getImageFormat (int id , const QByteArray& image); QString getImageFormat (int id , const QByteArray& image);
quint32 averageSizeForType (QString type); quint32 averageSizeForType (const QString& type);
int long2tileX(QString mapType, double lon, int z); int long2tileX(const QString& mapType, double lon, int z);
int lat2tileY(QString mapType, double lat, int z); int lat2tileY(const QString& mapType, double lat, int z);
QHash<QString, MapProvider*> getProviderTable(){return _providersTable;} QHash<QString, MapProvider*> getProviderTable(){return _providersTable;}
int getIdFromType(QString type); int getIdFromType(const QString& type);
QString getTypeFromId(int id); QString getTypeFromId(int id);
MapProvider* getMapProviderFromId(int id); MapProvider* getMapProviderFromId(int id);
QGCTileSet getTileCount(int zoom, double topleftLon, double topleftLat, QGCTileSet getTileCount(int zoom, double topleftLon, double topleftLat,
double bottomRightLon, double bottomRightLat, double bottomRightLon, double bottomRightLat,
QString mapType); const QString& mapType);
bool isElevation(int mapId); bool isElevation(int mapId);

6
src/QtLocationPlugin/QGCTileCacheWorker.cpp

@ -329,11 +329,11 @@ QGCCacheWorker::_getTile(QGCMapTask* mtask)
QString s = QString("SELECT tile, format, type FROM Tiles WHERE hash = \"%1\"").arg(task->hash()); QString s = QString("SELECT tile, format, type FROM Tiles WHERE hash = \"%1\"").arg(task->hash());
if(query.exec(s)) { if(query.exec(s)) {
if(query.next()) { if(query.next()) {
QByteArray ar = query.value(0).toByteArray(); const QByteArray& arrray = query.value(0).toByteArray();
QString format = query.value(1).toString(); const QString& format = query.value(1).toString();
QString type = getQGCMapEngine()->urlFactory()->getTypeFromId(query.value(2).toInt()); QString type = getQGCMapEngine()->urlFactory()->getTypeFromId(query.value(2).toInt());
qCDebug(QGCTileCacheLog) << "_getTile() (Found in DB) HASH:" << task->hash(); qCDebug(QGCTileCacheLog) << "_getTile() (Found in DB) HASH:" << task->hash();
QGCCacheTile* tile = new QGCCacheTile(task->hash(), ar, format, type); QGCCacheTile* tile = new QGCCacheTile(task->hash(), arrray, format, type);
task->setTileFetched(tile); task->setTileFetched(tile);
found = true; found = true;
} }

Loading…
Cancel
Save