Use faster data structures

This commit is contained in:
Martin Tůma 2018-11-10 19:34:45 +01:00
parent 8e9df6cc0e
commit 078fc93783
3 changed files with 18 additions and 16 deletions

View File

@ -1,7 +1,7 @@
#include <QByteArray> #include <QByteArray>
#include <QPainter> #include <QPainter>
#include <QDebug> #include <QDebug>
#include <QVariantMap> #include <QVariantHash>
#include "vector_tile.pb.h" #include "vector_tile.pb.h"
#include "style.h" #include "style.h"
#include "tile.h" #include "tile.h"
@ -40,6 +40,7 @@ static QVariant value(const vector_tile::Tile_Value &val)
class Feature class Feature
{ {
public: public:
Feature() : _data(0) {}
Feature(const vector_tile::Tile_Feature *data, const QVector<QString> *keys, Feature(const vector_tile::Tile_Feature *data, const QVector<QString> *keys,
const QVector<QVariant> *values) : _data(data) const QVector<QVariant> *values) : _data(data)
{ {
@ -61,11 +62,11 @@ public:
} }
} }
const QVariantMap &tags() const {return _tags;} const QVariantHash &tags() const {return _tags;}
const vector_tile::Tile_Feature *data() const {return _data;} const vector_tile::Tile_Feature *data() const {return _data;}
private: private:
QVariantMap _tags; QVariantHash _tags;
const vector_tile::Tile_Feature *_data; const vector_tile::Tile_Feature *_data;
}; };
@ -87,17 +88,18 @@ public:
for (int i = 0; i < data->values_size(); i++) for (int i = 0; i < data->values_size(); i++)
values.append(value(data->values(i))); values.append(value(data->values(i)));
_features.reserve(data->features_size());
for (int i = 0; i < data->features_size(); i++) for (int i = 0; i < data->features_size(); i++)
_features.append(Feature(&(data->features(i)), &keys, &values)); _features.append(Feature(&(data->features(i)), &keys, &values));
qSort(_features.begin(), _features.end(), cmp); qSort(_features.begin(), _features.end(), cmp);
} }
const QList<Feature> &features() const {return _features;} const QVector<Feature> &features() const {return _features;}
const vector_tile::Tile_Layer *data() const {return _data;} const vector_tile::Tile_Layer *data() const {return _data;}
private: private:
const vector_tile::Tile_Layer *_data; const vector_tile::Tile_Layer *_data;
QList<Feature> _features; QVector<Feature> _features;
}; };
static inline qint32 zigzag32decode(quint32 value) static inline qint32 zigzag32decode(quint32 value)

View File

@ -96,7 +96,7 @@ Style::Layer::Filter::Filter(const QJsonArray &json)
INVALID_FILTER(json); INVALID_FILTER(json);
} }
bool Style::Layer::Filter::match(const QVariantMap &tags) const bool Style::Layer::Filter::match(const QVariantHash &tags) const
{ {
switch (_type) { switch (_type) {
case None: case None:
@ -363,7 +363,7 @@ Style::Layer::Layer(const QJsonObject &json)
_paint = Paint(json["paint"].toObject()); _paint = Paint(json["paint"].toObject());
} }
bool Style::Layer::match(int zoom, const QVariantMap &tags) const bool Style::Layer::match(int zoom, const QVariantHash &tags) const
{ {
if (zoom >= 0) { if (zoom >= 0) {
if (_minZoom > 0 && zoom < _minZoom) if (_minZoom > 0 && zoom < _minZoom)
@ -397,7 +397,7 @@ void Style::Layer::drawPath(int zoom, const QPainterPath &path,
} }
void Style::Layer::drawSymbol(int zoom, const QPainterPath &path, void Style::Layer::drawSymbol(int zoom, const QPainterPath &path,
const QVariantMap &tags, Tile &tile) const const QVariantHash &tags, Tile &tile) const
{ {
if (_layout.keys().isEmpty()) if (_layout.keys().isEmpty())
return; return;
@ -455,13 +455,13 @@ bool Style::load(const QString &fileName)
return true; return true;
} }
bool Style::match(int layer, const QVariantMap &tags) bool Style::match(int layer, const QVariantHash &tags)
{ {
return _styles.at(layer).match(_zoom, tags); return _styles.at(layer).match(_zoom, tags);
} }
void Style::drawFeature(int layer, const QPainterPath &path, void Style::drawFeature(int layer, const QPainterPath &path,
const QVariantMap &tags, Tile &tile) const QVariantHash &tags, Tile &tile)
{ {
const Layer &sl = _styles.at(layer); const Layer &sl = _styles.at(layer);

View File

@ -3,7 +3,7 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QVariantMap> #include <QVariantHash>
#include <QStringList> #include <QStringList>
#include <QSet> #include <QSet>
#include <QPen> #include <QPen>
@ -26,11 +26,11 @@ public:
void setZoom(int zoom) {_zoom = zoom;} void setZoom(int zoom) {_zoom = zoom;}
const QStringList &sourceLayers() const {return _sourceLayers;} const QStringList &sourceLayers() const {return _sourceLayers;}
bool match(int layer, const QVariantMap &tags); bool match(int layer, const QVariantHash &tags);
void drawBackground(Tile &tile); void drawBackground(Tile &tile);
void drawFeature(int layer, const QPainterPath &path, void drawFeature(int layer, const QPainterPath &path,
const QVariantMap &tags, Tile &tile); const QVariantHash &tags, Tile &tile);
private: private:
class Layer { class Layer {
@ -42,10 +42,10 @@ private:
bool isBackground() const {return (_type == Background);} bool isBackground() const {return (_type == Background);}
bool isSymbol() const {return (_type == Symbol);} bool isSymbol() const {return (_type == Symbol);}
bool match(int zoom, const QVariantMap &tags) const; bool match(int zoom, const QVariantHash &tags) const;
void drawPath(int zoom, const QPainterPath &path, Tile &tile) const; void drawPath(int zoom, const QPainterPath &path, Tile &tile) const;
void drawSymbol(int zoom, const QPainterPath &path, void drawSymbol(int zoom, const QPainterPath &path,
const QVariantMap &tags, Tile &tile) const; const QVariantHash &tags, Tile &tile) const;
private: private:
enum Type { enum Type {
@ -61,7 +61,7 @@ private:
Filter() : _type(None) {} Filter() : _type(None) {}
Filter(const QJsonArray &json); Filter(const QJsonArray &json);
bool match(const QVariantMap &tags) const; bool match(const QVariantHash &tags) const;
private: private:
enum Type { enum Type {
None, Unknown, None, Unknown,