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.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@
1005132 13f79535-47bb-0310-9956-
ffa450edef68
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);
*
* @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