• Kosta's avatar
    short string optimization · 3caa86c9
    Kosta authored
    Since the payload (the `Data` union) of the current implementation of `GenericValue` is `12 bytes` (32 bit) or `16 bytes` (64 bit) it could store `UTF8`-encoded strings up to `10` or `14` chars plus the `terminating zero` character plus the string length:
    ``` C++
        struct ShortString {
            enum { MaxSize = sizeof(GenericValue::String) / sizeof(Ch) - sizeof(unsigned char) };
            Ch str[MaxSize];
            unsigned char length;
        };  // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
    
    ```
    
    This is achieved by introducing additional `kInlineStrFlag` and `kShortStringFlag` flags. When setting a new string value in `SetStringRaw(s, alloc)` it is first checked if the string is short enough to fit into the `inline string buffer` and if so the given source string will be copied into the new `ShortString` target instead of allocating additional memory for it.
    3caa86c9
Name
Last commit
Last update
bin Loading commit data...
build Loading commit data...
doc Loading commit data...
example Loading commit data...
include/rapidjson Loading commit data...
test Loading commit data...
thirdparty Loading commit data...
.gitignore Loading commit data...
.gitmodules Loading commit data...
.travis.yml Loading commit data...
license.txt Loading commit data...
readme.md Loading commit data...