You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/10/06 19:09:46 UTC

svn commit: r1005132 - in /incubator/thrift/trunk/lib/cpp/src: protocol/TBinaryProtocol.cpp transport/TTransport.h

Author: dreiss
Date: Wed Oct  6 17:09:46 2010
New Revision: 1005132

URL: http://svn.apache.org/viewvc?rev=1005132&view=rev
Log:
THRIFT-922. cpp: When reading strings, borrow first

Attempt to get a pointer to the internal transport buffer before copying
onto the heap.  This improves performance TFramedTransport and
TMemoryBuffer, and with TBufferedTransport if the string fits within the
buffer.

Modified:
    incubator/thrift/trunk/lib/cpp/src/protocol/TBinaryProtocol.cpp
    incubator/thrift/trunk/lib/cpp/src/transport/TTransport.h

Modified: incubator/thrift/trunk/lib/cpp/src/protocol/TBinaryProtocol.cpp
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/protocol/TBinaryProtocol.cpp?rev=1005132&r1=1005131&r2=1005132&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/protocol/TBinaryProtocol.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/protocol/TBinaryProtocol.cpp Wed Oct  6 17:09:46 2010
@@ -377,6 +377,15 @@ uint32_t TBinaryProtocol::readStringBody
     return result;
   }
 
+  // Try to borrow first
+  const uint8_t* borrow_buf;
+  uint32_t got = size;
+  if ((borrow_buf = trans_->borrow(NULL, &got))) {
+    str.assign((const char*)borrow_buf, size);
+    trans_->consume(size);
+    return size;
+  }
+
   // Use the heap here to prevent stack overflow for v. large strings
   if (size > string_buf_size_ || string_buf_ == NULL) {
     void* new_string_buf = std::realloc(string_buf_, (uint32_t)size);

Modified: incubator/thrift/trunk/lib/cpp/src/transport/TTransport.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TTransport.h?rev=1005132&r1=1005131&r2=1005132&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TTransport.h (original)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TTransport.h Wed Oct  6 17:09:46 2010
@@ -167,7 +167,10 @@ class TTransport {
    *
    * @oaram buf  A buffer where the data can be stored if needed.
    *             If borrow doesn't return buf, then the contents of
-   *             buf after the call are undefined.
+   *             buf after the call are undefined.  This parameter may be
+   *             NULL to indicate that the caller is not supplying storage,
+   *             but would like a pointer into an internal buffer, if
+   *             available.
    * @param len  *len should initially contain the number of bytes to borrow.
    *             If borrow succeeds, *len will contain the number of bytes
    *             available in the returned pointer.  This will be at least