Optimize storage of tiny strings (up to 3 characters)

This commit is contained in:
Benoit Blanchon
2025-04-09 08:55:08 +02:00
parent 7f75985e47
commit 91397f9f06
16 changed files with 229 additions and 57 deletions

View File

@ -63,6 +63,18 @@ TEST_CASE("JsonVariant::set() when there is enough memory") {
});
}
SECTION("char* (tiny string optimization)") {
char str[16];
strcpy(str, "abc");
bool result = variant.set(str);
strcpy(str, "def");
REQUIRE(result == true);
REQUIRE(variant == "abc"); // stores by copy
REQUIRE(spy.log() == AllocatorLog{});
}
SECTION("(char*)0") {
bool result = variant.set(static_cast<char*>(0));