From: Stepan Palamarchuk Date: Mon, 25 Apr 2016 21:12:21 +0000 (-0700) Subject: Remove unnecessary construction of IOBuf in Cursor X-Git-Tag: 2016.07.26~326 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=57e517a56bd048c902be1c1e1a0655316a5189a4;p=folly.git Remove unnecessary construction of IOBuf in Cursor Summary: This assignment is unnecessary, because in `for` loop we **always** call `cloneOneInto` that would assign another IOBuf to that IOBuf. Reviewed By: alikhtarov Differential Revision: D3215861 fb-gh-sync-id: ad87b99848aaae79f0870d49e0474f1abf0f28e5 fbshipit-source-id: ad87b99848aaae79f0870d49e0474f1abf0f28e5 --- diff --git a/folly/io/Cursor.h b/folly/io/Cursor.h index 74412ea6..3cf369e9 100644 --- a/folly/io/Cursor.h +++ b/folly/io/Cursor.h @@ -324,8 +324,6 @@ class CursorBase { } size_t cloneAtMost(folly::IOBuf& buf, size_t len) { - buf = folly::IOBuf(); - std::unique_ptr tmp; size_t copied = 0; for (int loopCount = 0; true; ++loopCount) { diff --git a/folly/io/test/IOBufCursorBenchmark.cpp b/folly/io/test/IOBufCursorBenchmark.cpp index e7142d9c..233f800b 100644 --- a/folly/io/test/IOBufCursorBenchmark.cpp +++ b/folly/io/test/IOBufCursorBenchmark.cpp @@ -76,6 +76,16 @@ BENCHMARK(skipBenchmark, iters) { } } +BENCHMARK(cloneBenchmark, iters) { + folly::IOBuf out; + while (iters--) { + Cursor c(iobuf_read_benchmark.get()); + for (int i = 0; i < benchmark_size; ++i) { + c.clone(out, 1); + } + } +} + // fbmake opt // _bin/folly/experimental/io/test/iobuf_cursor_test -benchmark //