🔨 only calculate array index string when needed #1098
This commit is contained in:
		
							parent
							
								
									90eb0a91e0
								
							
						
					
					
						commit
						481ace65c4
					
				
					 2 changed files with 22 additions and 16 deletions
				
			
		|  | @ -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: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue