-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
miloyip
merged 9 commits into
Tencent:master
from
Kosta-Github:Kosta/short_string_optimization
Sep 2, 2014
Merged
short string optimization #131
miloyip
merged 9 commits into
Tencent:master
from
Kosta-Github:Kosta/short_string_optimization
Sep 2, 2014
Commits on Sep 1, 2014
-
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.
Configuration menu - View commit details
-
Copy full SHA for 3caa86c - Browse repository at this point
Copy the full SHA 3caa86cView commit details -
code cleanup for
StringEqual()
Instead of replicating the functionality of `GetString()` and `GetStringLength()` in `StringEqual()` it now calls these methods instead.
Configuration menu - View commit details
-
Copy full SHA for b92d0eb - Browse repository at this point
Copy the full SHA b92d0ebView commit details -
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).
Configuration menu - View commit details
-
Copy full SHA for d2a374b - Browse repository at this point
Copy the full SHA d2a374bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 697cf40 - Browse repository at this point
Copy the full SHA 697cf40View commit details -
Configuration menu - View commit details
-
Copy full SHA for 056d0da - Browse repository at this point
Copy the full SHA 056d0daView commit details -
Configuration menu - View commit details
-
Copy full SHA for 88debcf - Browse repository at this point
Copy the full SHA 88debcfView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6099975 - Browse repository at this point
Copy the full SHA 6099975View commit details -
use
rapidjson::Value::SizeType
as the type for storing and comparin……g the string length
Configuration menu - View commit details
-
Copy full SHA for ba05ea5 - Browse repository at this point
Copy the full SHA ba05ea5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 08e8109 - Browse repository at this point
Copy the full SHA 08e8109View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.