mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-30 22:51:16 +01:00
Don't use a map where an array is fully suficient and much faster
This commit is contained in:
parent
3d4adba90a
commit
54db2a5a6c
@ -538,54 +538,53 @@ bool RGNFile::links(Handle &hdl, const SubDiv *subdiv, quint32 shift,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<RGNFile::SegmentType, SubDiv::Segment> RGNFile::segments(Handle &hdl,
|
bool RGNFile::segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) const
|
||||||
SubDiv *subdiv) const
|
|
||||||
{
|
{
|
||||||
QMap<SegmentType, SubDiv::Segment> ret;
|
|
||||||
|
|
||||||
if (subdiv->offset() == subdiv->end() || !(subdiv->objects() & 0x1F))
|
if (subdiv->offset() == subdiv->end() || !(subdiv->objects() & 0x1F))
|
||||||
return ret;
|
return true;
|
||||||
|
|
||||||
quint32 offset = _offset + subdiv->offset();
|
quint32 offset = _offset + subdiv->offset();
|
||||||
|
if (!seek(hdl, offset))
|
||||||
|
return false;
|
||||||
|
|
||||||
int no = 0;
|
int no = 0;
|
||||||
for (quint8 mask = 0x1; mask <= 0x10; mask <<= 1)
|
for (int i = 0; i < 5; i++)
|
||||||
if (subdiv->objects() & mask)
|
if (subdiv->objects() & (1<<i))
|
||||||
no++;
|
no++;
|
||||||
|
|
||||||
if (!seek(hdl, offset))
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
quint32 start = offset + 2 * (no - 1);
|
quint32 start = offset + 2 * (no - 1);
|
||||||
quint32 ls = 0;
|
quint32 ls = 0;
|
||||||
SegmentType lt = (SegmentType)0;
|
int lt = 0;
|
||||||
|
|
||||||
for (quint8 mask = 0x1; mask <= 0x10; mask <<= 1) {
|
for (int i = 0; i < 5; i++) {
|
||||||
if (subdiv->objects() & mask) {
|
if (subdiv->objects() & (1<<i)) {
|
||||||
if (ls) {
|
if (ls) {
|
||||||
quint16 po;
|
quint16 po;
|
||||||
if (!readUInt16(hdl, po) || !po)
|
if (!readUInt16(hdl, po) || !po)
|
||||||
return QMap<RGNFile::SegmentType, SubDiv::Segment>();
|
return false;
|
||||||
start = offset + po;
|
start = offset + po;
|
||||||
ret.insert(lt, SubDiv::Segment(ls, start));
|
seg[lt] = SubDiv::Segment(ls, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
lt = (SegmentType)mask;
|
lt = i;
|
||||||
ls = start;
|
ls = start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.insert(lt, SubDiv::Segment(ls, subdiv->end()
|
seg[lt] = SubDiv::Segment(ls,
|
||||||
? _offset + subdiv->end() : _offset + _size));
|
subdiv->end() ? _offset + subdiv->end() : _offset + _size);
|
||||||
|
|
||||||
return ret;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RGNFile::subdivInit(Handle &hdl, SubDiv *subdiv) const
|
bool RGNFile::subdivInit(Handle &hdl, SubDiv *subdiv) const
|
||||||
{
|
{
|
||||||
QMap<RGNFile::SegmentType, SubDiv::Segment> seg(segments(hdl, subdiv));
|
SubDiv::Segment seg[5];
|
||||||
SubDiv::Segment extPoints, extLines, extPolygons;
|
SubDiv::Segment extPoints, extLines, extPolygons;
|
||||||
|
|
||||||
|
if (!segments(hdl, subdiv, seg))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (subdiv->extPointsOffset() != subdiv->extPointsEnd()) {
|
if (subdiv->extPointsOffset() != subdiv->extPointsEnd()) {
|
||||||
quint32 start = _pointsOffset + subdiv->extPointsOffset();
|
quint32 start = _pointsOffset + subdiv->extPointsOffset();
|
||||||
quint32 end = subdiv->extPointsEnd()
|
quint32 end = subdiv->extPointsEnd()
|
||||||
@ -608,9 +607,8 @@ bool RGNFile::subdivInit(Handle &hdl, SubDiv *subdiv) const
|
|||||||
extLines = SubDiv::Segment(start, end);
|
extLines = SubDiv::Segment(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
subdiv->init(seg.value(Point), seg.value(IndexedPoint), seg.value(Line),
|
subdiv->init(seg[Point], seg[IndexedPoint], seg[Line], seg[Polygon],
|
||||||
seg.value(Polygon), seg.value(RoadReference), extPoints, extLines,
|
seg[RoadReference], extPoints, extLines, extPolygons);
|
||||||
extPolygons);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,11 @@ class RGNFile : public SubFile
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum SegmentType {
|
enum SegmentType {
|
||||||
Point = 0x1,
|
Point,
|
||||||
IndexedPoint = 0x2,
|
IndexedPoint,
|
||||||
Line = 0x4,
|
Line,
|
||||||
Polygon = 0x8,
|
Polygon,
|
||||||
RoadReference = 0x10
|
RoadReference
|
||||||
};
|
};
|
||||||
|
|
||||||
RGNFile(const IMGData *img)
|
RGNFile(const IMGData *img)
|
||||||
@ -61,8 +61,7 @@ public:
|
|||||||
quint32 dictSize() const {return _dictSize;}
|
quint32 dictSize() const {return _dictSize;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<SegmentType, SubDiv::Segment> segments(Handle &hdl, SubDiv *subdiv)
|
bool segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) const;
|
||||||
const;
|
|
||||||
bool readClassFields(Handle &hdl, SegmentType segmentType,
|
bool readClassFields(Handle &hdl, SegmentType segmentType,
|
||||||
MapData::Poly *poly = 0, const LBLFile *lbl = 0) const;
|
MapData::Poly *poly = 0, const LBLFile *lbl = 0) const;
|
||||||
bool skipLclFields(Handle &hdl, const quint32 flags[3]) const;
|
bool skipLclFields(Handle &hdl, const quint32 flags[3]) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user