mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
... you are too slow and QJson API is so ugly. Now using this wonderful json lib: https://github.com/nlohmann/json Results in release mode (QJson tests are not shown but QJson was even slower than string concat). PASS : TestQgsJsonUtils::testExportAttributesJson(Use json) RESULT : TestQgsJsonUtils::testExportAttributesJson():"Use json": 0.0022 msecs per iteration (total: 75, iterations: 32768) PASS : TestQgsJsonUtils::testExportAttributesJson(Use old string concat) RESULT : TestQgsJsonUtils::testExportAttributesJson():"Use old string concat": 0.0032 msecs per iteration (total: 54, iterations: 16384) PASS : TestQgsJsonUtils::testExportFeatureJson(Use json) RESULT : TestQgsJsonUtils::testExportFeatureJson():"Use json": 0.011 msecs per iteration (total: 96, iterations: 8192) PASS : TestQgsJsonUtils::testExportFeatureJson(Use old string concat) RESULT : TestQgsJsonUtils::testExportFeatureJson():"Use old string concat": 0.015 msecs per iteration (total: 64, iterations: 4096) PASS : TestQgsJsonUtils::testExportGeomToJson(Use json) RESULT : TestQgsJsonUtils::testExportGeomToJson():"Use json": 0.76 msecs per iteration (total: 98, iterations: 128) PASS : TestQgsJsonUtils::testExportGeomToJson(Use old string concat) RESULT : TestQgsJsonUtils::testExportGeomToJson():"Use old string concat": 0.85 msecs per iteration (total: 55, iterations: 64) PASS : TestQgsJsonUtils::cleanupTestCase()
121 lines
2.7 KiB
C++
121 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <cstddef> // ptrdiff_t
|
|
#include <limits> // numeric_limits
|
|
|
|
namespace nlohmann
|
|
{
|
|
namespace detail
|
|
{
|
|
/*
|
|
@brief an iterator for primitive JSON types
|
|
|
|
This class models an iterator for primitive JSON types (boolean, number,
|
|
string). It's only purpose is to allow the iterator/const_iterator classes
|
|
to "iterate" over primitive values. Internally, the iterator is modeled by
|
|
a `difference_type` variable. Value begin_value (`0`) models the begin,
|
|
end_value (`1`) models past the end.
|
|
*/
|
|
class primitive_iterator_t
|
|
{
|
|
private:
|
|
using difference_type = std::ptrdiff_t;
|
|
static constexpr difference_type begin_value = 0;
|
|
static constexpr difference_type end_value = begin_value + 1;
|
|
|
|
/// iterator as signed integer type
|
|
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
|
|
|
|
public:
|
|
constexpr difference_type get_value() const noexcept
|
|
{
|
|
return m_it;
|
|
}
|
|
|
|
/// set iterator to a defined beginning
|
|
void set_begin() noexcept
|
|
{
|
|
m_it = begin_value;
|
|
}
|
|
|
|
/// set iterator to a defined past the end
|
|
void set_end() noexcept
|
|
{
|
|
m_it = end_value;
|
|
}
|
|
|
|
/// return whether the iterator can be dereferenced
|
|
constexpr bool is_begin() const noexcept
|
|
{
|
|
return m_it == begin_value;
|
|
}
|
|
|
|
/// return whether the iterator is at end
|
|
constexpr bool is_end() const noexcept
|
|
{
|
|
return m_it == end_value;
|
|
}
|
|
|
|
friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
|
|
{
|
|
return lhs.m_it == rhs.m_it;
|
|
}
|
|
|
|
friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
|
|
{
|
|
return lhs.m_it < rhs.m_it;
|
|
}
|
|
|
|
primitive_iterator_t operator+(difference_type n) noexcept
|
|
{
|
|
auto result = *this;
|
|
result += n;
|
|
return result;
|
|
}
|
|
|
|
friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
|
|
{
|
|
return lhs.m_it - rhs.m_it;
|
|
}
|
|
|
|
primitive_iterator_t& operator++() noexcept
|
|
{
|
|
++m_it;
|
|
return *this;
|
|
}
|
|
|
|
primitive_iterator_t const operator++(int) noexcept
|
|
{
|
|
auto result = *this;
|
|
++m_it;
|
|
return result;
|
|
}
|
|
|
|
primitive_iterator_t& operator--() noexcept
|
|
{
|
|
--m_it;
|
|
return *this;
|
|
}
|
|
|
|
primitive_iterator_t const operator--(int) noexcept
|
|
{
|
|
auto result = *this;
|
|
--m_it;
|
|
return result;
|
|
}
|
|
|
|
primitive_iterator_t& operator+=(difference_type n) noexcept
|
|
{
|
|
m_it += n;
|
|
return *this;
|
|
}
|
|
|
|
primitive_iterator_t& operator-=(difference_type n) noexcept
|
|
{
|
|
m_it -= n;
|
|
return *this;
|
|
}
|
|
};
|
|
} // namespace detail
|
|
} // namespace nlohmann
|