diff options
author | Soheil Hassas Yeganeh <soheil@google.com> | 2018-09-25 17:50:45 -0400 |
---|---|---|
committer | Soheil Hassas Yeganeh <soheil@google.com> | 2018-09-25 17:50:45 -0400 |
commit | c1a1d66864a637f06b409b1768bc05a982b28949 (patch) | |
tree | 77ae0d58b4e68402e4234150fcc8516db7d4b66f /src/cpp | |
parent | ccbad108e45afb7c4fb361202cc0bae5ad7e5da2 (diff) |
Avoid allocating temporary strings in Channel::CreateCall().
Add `SliceFromArray()` which takes a `char*` instead of
`const string&`, to save string allocations for copying from a `char *`.
Use the new API to eliminate two string allocations and copies per call for
method and host names.
release-note: no
Diffstat (limited to 'src/cpp')
-rw-r--r-- | src/cpp/client/channel_cc.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc index c59059f045..5d1a9f4b96 100644 --- a/src/cpp/client/channel_cc.cc +++ b/src/cpp/client/channel_cc.cc @@ -20,6 +20,7 @@ #include <chrono> #include <condition_variable> +#include <cstring> #include <memory> #include <mutex> @@ -116,10 +117,11 @@ internal::Call Channel::CreateCall(const internal::RpcMethod& method, } else if (!host_.empty()) { host_str = host_.c_str(); } - grpc_slice method_slice = SliceFromCopiedString(method.name()); + grpc_slice method_slice = + SliceFromArray(method.name(), strlen(method.name())); grpc_slice host_slice; if (host_str != nullptr) { - host_slice = SliceFromCopiedString(host_str); + host_slice = SliceFromArray(host_str, strlen(host_str)); } c_call = grpc_channel_create_call( c_channel_, context->propagate_from_call_, |