added IOBuf::wrapBufferAsValue()
authorIlya Maykov <ilyam@fb.com>
Wed, 18 May 2016 01:53:27 +0000 (18:53 -0700)
committerFacebook Github Bot 4 <facebook-github-bot-4-bot@fb.com>
Wed, 18 May 2016 02:08:40 +0000 (19:08 -0700)
commit6b5a25fc7852dceb54178072fecb6e31d09252fd
tree3ebda04d4eb4b2a5f07af6830d4b04a635d73f17
parent4ffd39d6962255cf227b7dbda2f76a54759069ac
added IOBuf::wrapBufferAsValue()

Summary:
Added a version of IOBuf::wrapBuffer() which returns the new IOBuf by value rather than heap-allocating it.
Motivation: we have a lot of places in the crypto code that do something like this:

  // take a string or vector parameter
  auto buf = folly::IOBuf::wrapBuffer( /* string or vector goes here */);
  // do something with buf
  // return

In these cases, a stack-allocated IOBuf would save us from an unnecessary heap allocation. But calling `folly::IOBuf(folly::IOBuf::WrapBufferOp::WRAP_BUFFER, ...)` is gross and in practice people just call the much more readable `wrapBuffer()` function. Hypothesis: readability trumps performance, but if we had a readable version that returned a stack-allocated IOBuf, it might see usage.

Reviewed By: yfeldblum

Differential Revision: D3314037

fbshipit-source-id: 4d4b5ec1d067762a27de1d7d6f7cac406388bfa3
folly/io/IOBuf.cpp
folly/io/IOBuf.h
folly/io/test/IOBufTest.cpp