Remove unnecessary construction of IOBuf in Cursor
authorStepan Palamarchuk <stepan@fb.com>
Mon, 25 Apr 2016 21:12:21 +0000 (14:12 -0700)
committerFacebook Github Bot 0 <facebook-github-bot-0-bot@fb.com>
Mon, 25 Apr 2016 21:20:30 +0000 (14:20 -0700)
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
folly/io/test/IOBufCursorBenchmark.cpp

index 74412ea..3cf369e 100644 (file)
@@ -324,8 +324,6 @@ class CursorBase {
   }
 
   size_t cloneAtMost(folly::IOBuf& buf, size_t len) {
-    buf = folly::IOBuf();
-
     std::unique_ptr<folly::IOBuf> tmp;
     size_t copied = 0;
     for (int loopCount = 0; true; ++loopCount) {
index e7142d9..233f800 100644 (file)
@@ -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
 //