Add cloning constructor to folly::IOBuf
authorTudor Bosman <tudorb@fb.com>
Thu, 4 Jun 2015 00:20:40 +0000 (17:20 -0700)
committerNoam Lerner <noamler@fb.com>
Fri, 5 Jun 2015 02:31:22 +0000 (19:31 -0700)
Summary:
``` lang=cpp
folly::IOBuf buf(folly::IOBuf::CLONE, other);
```

is more convenient (and expression-friendly) than

``` lang=cpp
folly::IOBuf buf;
other.cloneInto(buf);
```

Test Plan: used it

Reviewed By: davejwatson@fb.com

Subscribers: net-systems@, folly-diffs@, yfeldblum, chalfant

FB internal diff: D2124605

Signature: t1:2124605:1433372767:c167a36ffdc6d20c740aa57895532e9445766fce

folly/io/IOBuf.h

index e5fd07b38146736198922f6000a42e3e6e8ecab3..c75dbe1da07f7a89189f599ed84076b2a39203cc 100644 (file)
@@ -232,6 +232,7 @@ class IOBuf {
   enum WrapBufferOp { WRAP_BUFFER };
   enum TakeOwnershipOp { TAKE_OWNERSHIP };
   enum CopyBufferOp { COPY_BUFFER };
+  enum CloneOp { CLONE };
 
   typedef ByteRange value_type;
   typedef Iterator iterator;
@@ -397,6 +398,13 @@ class IOBuf {
   IOBuf(CopyBufferOp op, ByteRange br,
         uint64_t headroom=0, uint64_t minTailroom=0);
 
+  /**
+   * Clone an IOBuf. See the notes for cloneInto().
+   */
+  IOBuf(CloneOp, const IOBuf& src) : IOBuf() {
+    src.cloneInto(*this);
+  }
+
   /**
    * Convenience function to create a new IOBuf object that copies data from a
    * user-supplied string, optionally allocating a given amount of