This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
feat: adds efficient move support to Value::get<string>() #980
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes googleapis#422 Changes `Value::get<T>()` to efficiently move `std::string` values out of the proto and directly to the caller. `std::string` is the only type that can do this because it's the only type which is exactly the same in the proto and outside of it. All other types require some type of decoding, which necessarily requires some amount of copying from the proto out to the caller.
Codecov Report
@@ Coverage Diff @@
## master #980 +/- ##
==========================================
- Coverage 94.17% 94.16% -0.01%
==========================================
Files 158 159 +1
Lines 10704 10753 +49
==========================================
+ Hits 10080 10126 +46
- Misses 624 627 +3
Continue to review full report at Codecov.
|
coryan
approved these changes
Oct 25, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this a feat:
, not a chore:
, but in either case
Reviewed 3 of 3 files at r1.
Reviewable status:complete! all files reviewed, all discussions resolved
Yep, changed to |
devjgm
added a commit
to devjgm/google-cloud-cpp
that referenced
this pull request
May 7, 2020
…/google-cloud-cpp-spanner#980) Fixes googleapis/google-cloud-cpp-spanner#422 Changes Value::get<T>() to efficiently move std::string values out of the proto and directly to the caller. std::string is the only type that can do this because it's the only type which is exactly the same in the proto and outside of it. All other types require some type of decoding, which necessarily requires some amount of copying from the proto out to the caller. Note: the unit tests verifying this behavior rely on unspecified behavior of std::string. Specifically that a moved-from large string ends up empty. This is not guaranteed, but it appears to the true in all cases that I've seen. So we rely on this behavior in the unit test. If this turns out to not be true on some platform, we'll have to adjust the unit tests. I've commented the tests about this.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #422
Changes
Value::get<T>()
to efficiently movestd::string
values outof the proto and directly to the caller.
std::string
is the only typethat can do this because it's the only type which is exactly the same in
the proto and outside of it. All other types require some type of
decoding, which necessarily requires some amount of copying from the
proto out to the caller.
Note: the unit tests verifying this behavior rely on unspecified behavior of std::string. Specifically that a moved-from large string ends up empty. This is not guaranteed, but it appears to the true in all cases that I've seen. So we rely on this behavior in the unit test. If this turns out to not be true on some platform, we'll have to adjust the unit tests. I've commented the tests about this.
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)