mirror of
https://github.com/nlohmann/json.git
synced 2026-10-11 08:57:15 +00:00
Release the list of large objects once load() has built the indexes
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
2 files changed
+27
No files matched your search
@@ -738,6 +738,7 @@ inline void load_image(document_data& d, const std::uint8_t* image, std::size_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
build_object_indexes(d);
|
build_object_indexes(d);
|
||||||
|
std::vector<std::uint32_t>().swap(d.large_objects); // (only needed while building)
|
||||||
d.discarded = false;
|
d.discarded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -373,6 +373,32 @@ TEST_CASE("json_view images: round trips")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("loading releases the list of large objects")
|
||||||
|
{
|
||||||
|
std::string text = "[";
|
||||||
|
for (int object = 0; object < 400; ++object)
|
||||||
|
{
|
||||||
|
text += object != 0 ? ",{" : "{";
|
||||||
|
for (int i = 0; i < 128; ++i)
|
||||||
|
{
|
||||||
|
text += (i != 0 ? ",\"" : "\"") + std::to_string(i) + "\":" + std::to_string(i);
|
||||||
|
}
|
||||||
|
text += '}';
|
||||||
|
}
|
||||||
|
text += "]";
|
||||||
|
json_document parsed = json_document::parse(text);
|
||||||
|
const std::vector<std::uint8_t> image = parsed.save();
|
||||||
|
json_document loaded = json_document::load(image);
|
||||||
|
CHECK(loaded.root()[399]["127"] == 127);
|
||||||
|
// Parsing and loading build the same tables, and keep nothing else:
|
||||||
|
// not the positions of the objects to index (2 KiB here). The slack
|
||||||
|
// covers the nodes in the header of the document, which are sized
|
||||||
|
// differently.
|
||||||
|
parsed.shrink_to_fit();
|
||||||
|
loaded.shrink_to_fit();
|
||||||
|
CHECK(loaded.memory_usage() <= parsed.memory_usage() + 512);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("json_view images: edited documents")
|
TEST_CASE("json_view images: edited documents")
|
||||||
|
|||||||
Reference in new issue
Block a user