Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

short string optimization #131

Merged

Commits on Sep 1, 2014

  1. short string optimization

    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.
    Kosta-Github committed Sep 1, 2014
    Configuration menu
    Copy the full SHA
    3caa86c View commit details
    Browse the repository at this point in the history
  2. code cleanup for StringEqual()

    Instead of replicating the functionality of `GetString()` and `GetStringLength()` in `StringEqual()` it now calls these methods instead.
    Kosta-Github committed Sep 1, 2014
    Configuration menu
    Copy the full SHA
    b92d0eb View commit details
    Browse the repository at this point in the history
  3. allow the short string optimization to store one more character

    The `ShortString` can represent zero-terminated strings up to `MaxSize` chars (excluding the terminating zero) and store a value to determine the length of the contained string in the last character `str[LenPos]` by storing `MaxSize - length` there. If the string to store has the maximal length of `MaxSize` (excluding the terminating zero) then `str[LenPos]` will store `0` and therefore act as the string terminator as well. For getting the string length back from that value just use `MaxSize - str[LenPos]`.
    
    This allows to store `11`-chars strings in 32-bit mode and `15`-chars strings in 64-bit mode inline (for `UTF8`-encoded strings).
    Kosta-Github committed Sep 1, 2014
    Configuration menu
    Copy the full SHA
    d2a374b View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    697cf40 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    056d0da View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    88debcf View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    6099975 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    ba05ea5 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    08e8109 View commit details
    Browse the repository at this point in the history