move io/Cursor-defs.h to io/Cursor.cpp
authorAdam Simpkins <simpkins@fb.com>
Thu, 26 May 2016 22:38:13 +0000 (15:38 -0700)
committerFacebook Github Bot 6 <facebook-github-bot-6-bot@fb.com>
Thu, 26 May 2016 22:57:18 +0000 (15:57 -0700)
Summary:
The two function definitions in this file are both normal function definitions,
not template functions.  Therefore this should be just a normal .cpp file, and
not a -defs.h header file.

Reviewed By: igorsugak

Differential Revision: D3348439

fbshipit-source-id: 3ebe49c84493f5aab06c568d9df15a37c2c48836

folly/Makefile.am
folly/io/Cursor-defs.h [deleted file]
folly/io/Cursor.cpp [new file with mode: 0644]
folly/io/test/IOBufCursorBenchmark.cpp
folly/io/test/IOBufCursorTest.cpp

index 1b28ff7ff88d336826c1ad18c04aa8a83874b691..275d2477edb02709ab7729931715223920af6c04 100644 (file)
@@ -401,6 +401,7 @@ libfolly_la_SOURCES = \
        IPAddressV6.cpp \
        LifoSem.cpp \
        io/Compression.cpp \
+       io/Cursor.cpp \
        io/IOBuf.cpp \
        io/IOBufQueue.cpp \
        io/RecordIO.cpp \
diff --git a/folly/io/Cursor-defs.h b/folly/io/Cursor-defs.h
deleted file mode 100644 (file)
index 078c429..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2016 Facebook, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <folly/io/Cursor.h>
-
-#include <cstdio>
-#include <folly/ScopeGuard.h>
-
-namespace folly { namespace io {
-
-void Appender::printf(const char* fmt, ...) {
-  va_list ap;
-  va_start(ap, fmt);
-  vprintf(fmt, ap);
-  va_end(ap);
-}
-
-void Appender::vprintf(const char* fmt, va_list ap) {
-  // Make a copy of ap in case we need to retry.
-  // We use ap on the first attempt, so it always gets advanced
-  // passed the used arguments.  We'll only use apCopy if we need to retry.
-  va_list apCopy;
-  va_copy(apCopy, ap);
-  SCOPE_EXIT {
-    va_end(apCopy);
-  };
-
-  // First try writing into our available data space.
-  int ret = vsnprintf(reinterpret_cast<char*>(writableData()), length(),
-                      fmt, ap);
-  if (ret < 0) {
-    throw std::runtime_error("error formatting printf() data");
-  }
-  // vsnprintf() returns the number of characters that would be printed,
-  // not including the terminating nul.
-  if (size_t(ret) < length()) {
-    // All of the data was successfully written.
-    append(ret);
-    return;
-  }
-
-  // There wasn't enough room for the data.
-  // Allocate more room, and then retry.
-  ensure(ret + 1);
-  ret = vsnprintf(reinterpret_cast<char*>(writableData()), length(),
-                  fmt, apCopy);
-  if (ret < 0) {
-    throw std::runtime_error("error formatting printf() data");
-  }
-  if (size_t(ret) >= length()) {
-    // This shouldn't ever happen.
-    throw std::runtime_error("unexpectedly out of buffer space on second "
-                             "vsnprintf() attmept");
-  }
-  append(ret);
-}
-
-}}  // folly::io
diff --git a/folly/io/Cursor.cpp b/folly/io/Cursor.cpp
new file mode 100644 (file)
index 0000000..fe47840
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2016 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <folly/io/Cursor.h>
+
+#include <cstdio>
+#include <folly/ScopeGuard.h>
+
+namespace folly { namespace io {
+
+void Appender::printf(const char* fmt, ...) {
+  va_list ap;
+  va_start(ap, fmt);
+  vprintf(fmt, ap);
+  va_end(ap);
+}
+
+void Appender::vprintf(const char* fmt, va_list ap) {
+  // Make a copy of ap in case we need to retry.
+  // We use ap on the first attempt, so it always gets advanced
+  // passed the used arguments.  We'll only use apCopy if we need to retry.
+  va_list apCopy;
+  va_copy(apCopy, ap);
+  SCOPE_EXIT {
+    va_end(apCopy);
+  };
+
+  // First try writing into our available data space.
+  int ret = vsnprintf(reinterpret_cast<char*>(writableData()), length(),
+                      fmt, ap);
+  if (ret < 0) {
+    throw std::runtime_error("error formatting printf() data");
+  }
+  // vsnprintf() returns the number of characters that would be printed,
+  // not including the terminating nul.
+  if (size_t(ret) < length()) {
+    // All of the data was successfully written.
+    append(ret);
+    return;
+  }
+
+  // There wasn't enough room for the data.
+  // Allocate more room, and then retry.
+  ensure(ret + 1);
+  ret = vsnprintf(reinterpret_cast<char*>(writableData()), length(),
+                  fmt, apCopy);
+  if (ret < 0) {
+    throw std::runtime_error("error formatting printf() data");
+  }
+  if (size_t(ret) >= length()) {
+    // This shouldn't ever happen.
+    throw std::runtime_error("unexpectedly out of buffer space on second "
+                             "vsnprintf() attmept");
+  }
+  append(ret);
+}
+
+}}  // folly::io
index 559f7a3eb972b71fad2a3442f07140fc9df1e465..465691c0dc71503645ec4e266e9a9c56fc808f79 100644 (file)
@@ -20,7 +20,6 @@
 #include <folly/Format.h>
 #include <folly/Range.h>
 #include <folly/io/Cursor.h>
-#include <folly/io/Cursor-defs.h>
 
 DECLARE_bool(benchmark);
 
index 958f6d4589fea1cddf8ce1fa87dcb5537aed91f7..a5bc4eb982983c55b803d2406d8ed123ae09d165 100644 (file)
@@ -19,7 +19,6 @@
 #include <folly/Format.h>
 #include <folly/Range.h>
 #include <folly/io/Cursor.h>
-#include <folly/io/Cursor-defs.h>
 
 #include <gtest/gtest.h>