Commit 137c9839 authored by Volker Krause's avatar Volker Krause Committed by Torsten Rahn
Browse files

Make geodata_cast not allocate

This is used on numerous hot paths, as having a cast function doing
(temporary) allocations is highly surprising.
parent b57d3924
......@@ -115,7 +115,7 @@ T *geodata_cast(GeoDataObject *node)
return nullptr;
}
if (node->nodeType() == T().nodeType()) {
if (typeid(*node) == typeid(T)) {
return static_cast<T *>(node);
}
......@@ -136,7 +136,7 @@ const T *geodata_cast(const GeoDataObject *node)
return nullptr;
}
if (node->nodeType() == T().nodeType()) {
if (typeid(*node) == typeid(T)) {
return static_cast<const T *>(node);
}
......
......@@ -12,6 +12,8 @@
#include <QDebug>
#include "GeoDataDocument.h"
#include "GeoDataFolder.h"
#include "GeoDataLinearRing.h"
#include "GeoDataLineString.h"
#include "GeoDataPlacemark.h"
#include "GeoDataCoordinates.h"
#include "GeoDataLatLonAltBox.h"
......@@ -30,6 +32,7 @@ class TestGeoData : public QObject
private Q_SLOTS:
void nodeTypeTest();
void parentingTest();
void testCast();
};
/// test the nodeType function through various construction tests
......@@ -130,6 +133,26 @@ void TestGeoData::parentingTest()
QCOMPARE( placemark2->style()->iconStyle().iconPath(), QString( "myicon.png" ) );
}
void TestGeoData::testCast()
{
GeoDataLineString obj;
GeoDataObject *base = &obj;
QCOMPARE(geodata_cast<GeoDataObject>(base), nullptr);
QCOMPARE(geodata_cast<GeoDataGeometry>(base), nullptr);
QCOMPARE(geodata_cast<GeoDataLineString>(base), &obj);
QCOMPARE(geodata_cast<GeoDataLinearRing>(base), nullptr);
QCOMPARE(geodata_cast<GeoDataPlacemark>(base), nullptr);
const GeoDataObject *cbase = &obj;
QCOMPARE(geodata_cast<GeoDataObject>(cbase), nullptr);
QCOMPARE(geodata_cast<GeoDataGeometry>(cbase), nullptr);
QCOMPARE(geodata_cast<GeoDataLineString>(cbase), &obj);
QCOMPARE(geodata_cast<GeoDataLinearRing>(cbase), nullptr);
QCOMPARE(geodata_cast<GeoDataPlacemark>(cbase), nullptr);
QCOMPARE(geodata_cast<GeoDataPlacemark>(static_cast<GeoDataObject*>(nullptr)), nullptr);
}
}
QTEST_MAIN( Marble::TestGeoData )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment