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

Commit 07dbbc4

Browse files
authored
feat: optimize passing Bytes to Value (#1104)
Now with more move support. Fixes #1103
1 parent 56be5a2 commit 07dbbc4

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

google/cloud/spanner/bytes.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ StatusOr<Bytes> BytesFromBase64(std::string input) {
148148
}
149149

150150
// Conversion to a base64-encoded US-ASCII `std::string`.
151-
std::string BytesToBase64(Bytes const& b) { return b.base64_rep_; }
151+
std::string BytesToBase64(Bytes b) { return std::move(b.base64_rep_); }
152152

153153
} // namespace internal
154154
} // namespace SPANNER_CLIENT_NS

google/cloud/spanner/bytes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Bytes; // defined below
3232
// Internal forward declarations to befriend.
3333
namespace internal {
3434
StatusOr<Bytes> BytesFromBase64(std::string input);
35-
std::string BytesToBase64(Bytes const& b);
35+
std::string BytesToBase64(Bytes b);
3636
} // namespace internal
3737

3838
/**
@@ -79,7 +79,7 @@ class Bytes {
7979

8080
private:
8181
friend StatusOr<Bytes> internal::BytesFromBase64(std::string input);
82-
friend std::string internal::BytesToBase64(Bytes const& b);
82+
friend std::string internal::BytesToBase64(Bytes b);
8383

8484
struct Encoder {
8585
Encoder(std::string& rep) : rep_(rep), len_(0) {}

google/cloud/spanner/value.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ google::protobuf::Value Value::MakeValueProto(std::string s) {
232232
return v;
233233
}
234234

235-
google::protobuf::Value Value::MakeValueProto(Bytes const& bytes) {
235+
google::protobuf::Value Value::MakeValueProto(Bytes bytes) {
236236
google::protobuf::Value v;
237-
v.set_string_value(internal::BytesToBase64(bytes));
237+
v.set_string_value(internal::BytesToBase64(std::move(bytes)));
238238
return v;
239239
}
240240

google/cloud/spanner/value.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class Value {
428428
static google::protobuf::Value MakeValueProto(std::int64_t i);
429429
static google::protobuf::Value MakeValueProto(double d);
430430
static google::protobuf::Value MakeValueProto(std::string s);
431-
static google::protobuf::Value MakeValueProto(Bytes const& b);
431+
static google::protobuf::Value MakeValueProto(Bytes b);
432432
static google::protobuf::Value MakeValueProto(Timestamp ts);
433433
static google::protobuf::Value MakeValueProto(Date d);
434434
static google::protobuf::Value MakeValueProto(int i);

0 commit comments

Comments
 (0)