From: Ben Craig Date: Wed, 9 Oct 2013 20:26:05 +0000 (-0500) Subject: THRIFT-2021: Improve large binary protocol string performance X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=fd64c15c4fa5ab092ecdda713bae142c05aafd72;p=common%2Fthrift.git THRIFT-2021: Improve large binary protocol string performance Client: cpp Patch: Ben Craig --- diff --git a/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc b/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc index 54d79b74..40226a5d 100644 --- a/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc +++ b/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc @@ -446,17 +446,8 @@ uint32_t TBinaryProtocolT::readStringBody(StrType& str, return size; } - // Use the heap here to prevent stack overflow for v. large strings - if (size > this->string_buf_size_ || this->string_buf_ == NULL) { - void* new_string_buf = std::realloc(this->string_buf_, (uint32_t)size); - if (new_string_buf == NULL) { - throw std::bad_alloc(); - } - this->string_buf_ = (uint8_t*)new_string_buf; - this->string_buf_size_ = size; - } - this->trans_->readAll(this->string_buf_, size); - str.assign((char*)this->string_buf_, size); + str.resize(size); + this->trans_->readAll(reinterpret_cast(&str[0]), size); return (uint32_t)size; }