You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by be...@apache.org on 2013/10/09 22:26:54 UTC

git commit: THRIFT-2021: Improve large binary protocol string performance Client: cpp Patch: Ben Craig

Updated Branches:
  refs/heads/master 96ea9daf8 -> fd64c15c4


THRIFT-2021: Improve large binary protocol string performance
Client: cpp
Patch: Ben Craig


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/fd64c15c
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/fd64c15c
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/fd64c15c

Branch: refs/heads/master
Commit: fd64c15c4fa5ab092ecdda713bae142c05aafd72
Parents: 96ea9da
Author: Ben Craig <be...@apache.org>
Authored: Wed Oct 9 15:26:05 2013 -0500
Committer: Ben Craig <be...@apache.org>
Committed: Wed Oct 9 15:26:05 2013 -0500

----------------------------------------------------------------------
 lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/fd64c15c/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc b/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
index 54d79b7..40226a5 100644
--- a/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
+++ b/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
@@ -446,17 +446,8 @@ uint32_t TBinaryProtocolT<Transport_>::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<uint8_t *>(&str[0]), size);
   return (uint32_t)size;
 }