🔨 only calculate array index string when needed #1098

parent 90eb0a91
......@@ -21,8 +21,10 @@ template<typename IteratorType> class iteration_proxy
IteratorType anchor;
/// an index for arrays (used to create key names)
std::size_t array_index = 0;
/// last stringified array index
mutable std::size_t array_index_last = 0;
/// a string representation of the array index
std::string array_index_str = "0";
mutable std::string array_index_str = "0";
/// an empty string (to return a reference for primitive values)
const std::string empty_str = "";
......@@ -39,13 +41,7 @@ template<typename IteratorType> class iteration_proxy
iteration_proxy_internal& operator++()
{
++anchor;
assert(anchor.m_object != nullptr);
if (anchor.m_object->is_array())
{
// update array index and string representation
array_index_str = std::to_string(++array_index);
}
++array_index;
return *this;
}
......@@ -65,7 +61,14 @@ template<typename IteratorType> class iteration_proxy
{
// use integer array index as key
case value_t::array:
{
if (array_index != array_index_last)
{
array_index_str = std::to_string(array_index);
array_index_last = array_index;
}
return array_index_str;
}
// use key from the object
case value_t::object:
......
......@@ -4691,8 +4691,10 @@ template<typename IteratorType> class iteration_proxy
IteratorType anchor;
/// an index for arrays (used to create key names)
std::size_t array_index = 0;
/// last stringified array index
mutable std::size_t array_index_last = 0;
/// a string representation of the array index
std::string array_index_str = "0";
mutable std::string array_index_str = "0";
/// an empty string (to return a reference for primitive values)
const std::string empty_str = "";
......@@ -4709,13 +4711,7 @@ template<typename IteratorType> class iteration_proxy
iteration_proxy_internal& operator++()
{
++anchor;
assert(anchor.m_object != nullptr);
if (anchor.m_object->is_array())
{
// update array index and string representation
array_index_str = std::to_string(++array_index);
}
++array_index;
return *this;
}
......@@ -4735,7 +4731,14 @@ template<typename IteratorType> class iteration_proxy
{
// use integer array index as key
case value_t::array:
{
if (array_index != array_index_last)
{
array_index_str = std::to_string(array_index);
array_index_last = array_index;
}
return array_index_str;
}
// use key from the object
case value_t::object:
......
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