Add mechanizm for caching local and peer addresses in AsyncSSLSocket.
[folly.git] / folly / Format.cpp
index b09152daf1f7b82533f162e33683086cad8e7f96..64e2cae56273771f47e1423fa1e6d81d6e70ee3a 100644 (file)
@@ -48,11 +48,11 @@ void FormatValue<double>::formatHelper(
   }
 
   // 2+: for null terminator and optional sign shenanigans.
-  char buf[2 + std::max({
-      (2 + DoubleToStringConverter::kMaxFixedDigitsBeforePoint +
-       DoubleToStringConverter::kMaxFixedDigitsAfterPoint),
-      (8 + DoubleToStringConverter::kMaxExponentialDigits),
-      (7 + DoubleToStringConverter::kMaxPrecisionDigits)})];
+  char buf[2 + std::max(
+      2 + DoubleToStringConverter::kMaxFixedDigitsBeforePoint +
+       DoubleToStringConverter::kMaxFixedDigitsAfterPoint,
+      std::max(8 + DoubleToStringConverter::kMaxExponentialDigits,
+      7 + DoubleToStringConverter::kMaxPrecisionDigits))];
   StringBuilder builder(buf + 1, static_cast<int> (sizeof(buf) - 1));
 
   char plusSign;
@@ -209,12 +209,25 @@ void FormatArg::initSlow() {
       if (++p == end) return;
     }
 
-    if (*p >= '0' && *p <= '9') {
-      auto b = p;
+    auto readInt = [&] {
+      auto const b = p;
       do {
         ++p;
       } while (p != end && *p >= '0' && *p <= '9');
-      width = to<int>(StringPiece(b, p));
+      return to<int>(StringPiece(b, p));
+    };
+
+    if (*p == '*') {
+      width = kDynamicWidth;
+      ++p;
+
+      if (p == end) return;
+
+      if (*p >= '0' && *p <= '9') widthIndex = readInt();
+
+      if (p == end) return;
+    } else if (*p >= '0' && *p <= '9') {
+      width = readInt();
 
       if (p == end) return;
     }
@@ -287,7 +300,6 @@ void insertThousandsGroupingUnsafe(char* start_buffer, char** end_buffer) {
   uint32_t buffer_read_index = remaining_digits - 1;
   start_buffer[buffer_write_index + 1] = 0;
 
-  uint32_t count = 0;
   bool done = false;
   uint32_t next_group_size = 3;