From 57e517a56bd048c902be1c1e1a0655316a5189a4 Mon Sep 17 00:00:00 2001 From: Stepan Palamarchuk Date: Mon, 25 Apr 2016 14:12:21 -0700 Subject: [PATCH] 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 --- folly/io/Cursor.h | 2 -- folly/io/test/IOBufCursorBenchmark.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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 // -- 2.34.1