Skip to content

Commit

Permalink
perf(MapEngine): avoid some unnecessary string copies
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardosimovic committed Jul 26, 2023
1 parent 6ccaef7 commit 9bd0911
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/QtLocationPlugin/QGCMapEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ QGCMapEngine::addTask(QGCMapTask* task)

//-----------------------------------------------------------------------------
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);
cacheTile(type, hash, image, format, set);
}

//-----------------------------------------------------------------------------
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();
//-- If we are allowed to persist data, save tile to cache
Expand All @@ -220,7 +220,7 @@ QGCMapEngine::cacheTile(QString type, const QString& hash, const QByteArray& ima

//-----------------------------------------------------------------------------
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);
}
Expand All @@ -235,7 +235,7 @@ QGCMapEngine::hashToType(const QString& hash)

//-----------------------------------------------------------------------------
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);
QGCFetchTileTask* task = new QGCFetchTileTask(hash);
Expand All @@ -244,7 +244,7 @@ QGCMapEngine::createFetchTileTask(QString type, int x, int y, int z)

//-----------------------------------------------------------------------------
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 > MAX_MAP_ZOOM) zoom = MAX_MAP_ZOOM;
Expand Down Expand Up @@ -368,7 +368,7 @@ QGCMapEngine::_pruned()

//-----------------------------------------------------------------------------
int
QGCMapEngine::concurrentDownloads(QString type)
QGCMapEngine::concurrentDownloads(const QString& type)
{
Q_UNUSED(type);
// TODO : We may want different values depending on
Expand Down
16 changes: 8 additions & 8 deletions src/QtLocationPlugin/QGCMapEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class QGCMapEngine : public QObject

void init ();
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 (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);
void cacheTile (const QString& type, int x, int y, int z, 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 (const QString& type, int x, int y, int z);
QStringList getMapNameList ();
const QString userAgent () { return _userAgent; }
void setUserAgent (const QString& ua) { _userAgent = ua; }
QString hashToType (const QString& hash);
QString hashToType (const QString& hash);
quint32 getMaxDiskCache ();
void setMaxDiskCache (quint32 size);
quint32 getMaxMemCache ();
Expand All @@ -56,13 +56,13 @@ class QGCMapEngine : public QObject
UrlFactory* urlFactory () { return _urlFactory; }

//-- Tile Math
static QGCTileSet getTileCount (int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, QString mapType);
static QString getTileHash (QString type, int x, int y, int z);
static QString getTypeFromName (const QString &name);
static QGCTileSet getTileCount (int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, const QString& mapType);
static QString getTileHash (const QString& type, int x, int y, int z);
static QString getTypeFromName (const QString& name);
static QString bigSizeToString (quint64 size);
static QString storageFreeSizeToString(quint64 size_MB);
static QString numberToString (quint64 number);
static int concurrentDownloads (QString type);
static int concurrentDownloads (const QString& type);

private slots:
void _updateTotals (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize);
Expand Down
19 changes: 12 additions & 7 deletions src/QtLocationPlugin/QGCMapUrlEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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()) {
return _providersTable[type]->getImageFormat(image);
} else {
Expand All @@ -130,7 +130,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) {
if (_providersTable.find(type) != _providersTable.end()) {
return _providersTable[type]->getTileURL(x, y, zoom, networkManager);
Expand All @@ -140,7 +140,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()) {
return _providersTable[type]->getAverageSize();
}
Expand Down Expand Up @@ -180,29 +180,34 @@ MapProvider* UrlFactory::getMapProviderFromId(int id)
return nullptr;
}

//-----------------------------------------------------------------------------
// Todo : qHash produce a uint bigger than max(int)
// There is still a low probability for this to
// 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
UrlFactory::long2tileX(QString mapType, double lon, int z)
UrlFactory::long2tileX(const QString& mapType, double lon, int z)
{
return _providersTable[mapType]->long2tileX(lon, z);
}

//-----------------------------------------------------------------------------
int
UrlFactory::lat2tileY(QString mapType, double lat, int z)
UrlFactory::lat2tileY(const QString& mapType, double lat, int z)
{
return _providersTable[mapType]->lat2tileY(lat, z);
}


//-----------------------------------------------------------------------------
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);
}
Expand Down
14 changes: 7 additions & 7 deletions src/QtLocationPlugin/QGCMapUrlEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@ class UrlFactory : public QObject {
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);

QString getImageFormat (QString type, const QByteArray& image);
QString getImageFormat (const QString& type, 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 lat2tileY(QString mapType, double lat, int z);
int long2tileX(const QString& mapType, double lon, int z);
int lat2tileY(const QString& mapType, double lat, int z);

QHash<QString, MapProvider*> getProviderTable(){return _providersTable;}

int getIdFromType(QString type);
int getIdFromType(const QString& type);
QString getTypeFromId(int id);
MapProvider* getMapProviderFromId(int id);

QGCTileSet getTileCount(int zoom, double topleftLon, double topleftLat,
double bottomRightLon, double bottomRightLat,
QString mapType);
const QString& mapType);

bool isElevation(int mapId);

Expand Down

0 comments on commit 9bd0911

Please sign in to comment.