Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

feat: adds efficient move support to Value::get<string>() #980

Merged
merged 2 commits into from
Oct 25, 2019

Conversation

devjgm
Copy link
Contributor

@devjgm devjgm commented Oct 25, 2019

Fixes #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.


This change is Reviewable

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.
@devjgm devjgm requested a review from coryan October 25, 2019 02:03
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 25, 2019
@codecov
Copy link

codecov bot commented Oct 25, 2019

Codecov Report

Merging #980 into master will decrease coverage by <.01%.
The diff coverage is 92.72%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
google/cloud/spanner/value_test.cc 99.09% <100%> (+0.08%) ⬆️
google/cloud/spanner/value.cc 97.1% <75%> (-0.53%) ⬇️
google/cloud/spanner/value.h 91.8% <86.36%> (-1.72%) ⬇️
...loud/spanner/internal/partial_result_set_resume.cc 90.9% <0%> (-4.55%) ⬇️
...ud/spanner/integration_tests/client_stress_test.cc 81.57% <0%> (-1.76%) ⬇️
google/cloud/spanner/transaction.h 100% <0%> (ø) ⬆️
google/cloud/spanner/database_admin_connection.h 100% <0%> (ø)
...anner/integration_tests/client_integration_test.cc 99.45% <0%> (ø) ⬆️
...loud/spanner/internal/partial_result_set_source.cc 94.36% <0%> (+1.4%) ⬆️
...on_tests/rpc_failure_threshold_integration_test.cc 87.64% <0%> (+2.08%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d95695b...bdcde8d. Read the comment docs.

Copy link
Member

@coryan coryan left a 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 :lgtm:

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@devjgm devjgm changed the title chore: adds efficient move support to Value::get<string>() feat: adds efficient move support to Value::get<string>() Oct 25, 2019
@devjgm
Copy link
Contributor Author

devjgm commented Oct 25, 2019

Yep, changed to feat:, thanks for pointing that out. I also spotted a typo in a comment that I changed: frong -> from.

@devjgm devjgm merged commit 21665f7 into googleapis:master Oct 25, 2019
@devjgm devjgm deleted the value-rvalue-get branch October 25, 2019 13:28
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.
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a Value::get<T>() && overload to allow moving out of Value
3 participants