From: Tudor Bosman Date: Thu, 4 Jun 2015 00:20:40 +0000 (-0700) Subject: Add cloning constructor to folly::IOBuf X-Git-Tag: v0.43.0~5 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a3537a0f553e89ca911745fa2e58db454044fb6b;p=folly.git Add cloning constructor to folly::IOBuf 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 --- diff --git a/folly/io/IOBuf.h b/folly/io/IOBuf.h index e5fd07b3..c75dbe1d 100644 --- a/folly/io/IOBuf.h +++ b/folly/io/IOBuf.h @@ -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