From 96503e3c72d19ec228189bb89fe214eadb4ffaa2 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 22 Oct 2020 01:59:43 -0700 Subject: [PATCH] Reduce code paths --- include/grpcpp/impl/codegen/call_op_set.h | 48 +++++++++++++---------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/include/grpcpp/impl/codegen/call_op_set.h b/include/grpcpp/impl/codegen/call_op_set.h index 8b6b1fdbed2..1d4392b46df 100644 --- a/include/grpcpp/impl/codegen/call_op_set.h +++ b/include/grpcpp/impl/codegen/call_op_set.h @@ -330,6 +330,7 @@ class CallOpSendMessage { } void FinishOp(bool* status) { if (msg_ == nullptr && !send_buf_.Valid()) return; + send_buf_.Clear(); if (hijacked_ && failed_send_) { // Hijacking interceptor failed this Op *status = false; @@ -378,9 +379,33 @@ class CallOpSendMessage { template Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { write_options_ = options; + // Serialize immediately since we do not have access to the message pointer + bool own_buf; + // TODO(vjpai): Remove the void below when possible + // The void in the template parameter below should not be needed + // (since it should be implicit) but is needed due to an observed + // difference in behavior between clang and gcc for certain internal users + Status result = SerializationTraits::Serialize( + message, send_buf_.bbuf_ptr(), &own_buf); + if (!own_buf) { + send_buf_.Duplicate(); + } + return result; +} + +template +Status CallOpSendMessage::SendMessage(const M& message) { + return SendMessage(message, WriteOptions()); +} + +template +Status CallOpSendMessage::SendMessagePtr(const M* message, + WriteOptions options) { + msg_ = message; + write_options_ = options; + // Store the serializer for later since we have access to the message serializer_ = [this](const void* message) { bool own_buf; - send_buf_.Clear(); // TODO(vjpai): Remove the void below when possible // The void in the template parameter below should not be needed // (since it should be implicit) but is needed due to an observed @@ -392,31 +417,12 @@ Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { } return result; }; - // Serialize immediately only if we do not have access to the message pointer - if (msg_ == nullptr) { - Status result = serializer_(&message); - serializer_ = nullptr; - return result; - } return Status(); } -template -Status CallOpSendMessage::SendMessage(const M& message) { - return SendMessage(message, WriteOptions()); -} - -template -Status CallOpSendMessage::SendMessagePtr(const M* message, - WriteOptions options) { - msg_ = message; - return SendMessage(*message, options); -} - template Status CallOpSendMessage::SendMessagePtr(const M* message) { - msg_ = message; - return SendMessage(*message, WriteOptions()); + return SendMessagePtr(message, WriteOptions()); } template