-
Knut Anders Hatlen authored
Json_wrapper_object_iterator creates a std::string object to hold the key for every key/value pair it iterates over. If the key names are long, or when running on a platform that doesn't implement the small string optimization, this could result in a heap allocation for every member in the JSON object that is being iterated over. This patch changes Json_wrapper_object_iterator so that it returns a pointer to the key name and the length of the key instead of a std::string object with the key name. The pointer points into already allocated memory for the key in the DOM or binary data structure, so that no new heap memory needs to be allocated while iterating. Microbenchmarks (64-bit, Intel Core i7-4770 3.4 GHz, GCC 8.2.0): BM_JsonWrapperObjectIteratorBinary 45733 ns/iter -> 21840 ns/iter [+109%] BM_JsonWrapperObjectIteratorDOM 41063 ns/iter -> 22504 ns/iter [ +82%] Change-Id: I8761e23f98f5bf04076f101a041ad2c74c76ef6e
Knut Anders Hatlen authoredJson_wrapper_object_iterator creates a std::string object to hold the key for every key/value pair it iterates over. If the key names are long, or when running on a platform that doesn't implement the small string optimization, this could result in a heap allocation for every member in the JSON object that is being iterated over. This patch changes Json_wrapper_object_iterator so that it returns a pointer to the key name and the length of the key instead of a std::string object with the key name. The pointer points into already allocated memory for the key in the DOM or binary data structure, so that no new heap memory needs to be allocated while iterating. Microbenchmarks (64-bit, Intel Core i7-4770 3.4 GHz, GCC 8.2.0): BM_JsonWrapperObjectIteratorBinary 45733 ns/iter -> 21840 ns/iter [+109%] BM_JsonWrapperObjectIteratorDOM 41063 ns/iter -> 22504 ns/iter [ +82%] Change-Id: I8761e23f98f5bf04076f101a041ad2c74c76ef6e
Loading