about summary refs log tree commit diff
path: root/absl/strings/internal/str_format/arg.cc
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-02-14T17·41-0800
committerMark Barolak <mbar@google.com>2020-02-14T17·54-0500
commit3c814105108680997d0821077694f663693b5382 (patch)
treef414158f000b24926b4110dd1c3a640106fe630c /absl/strings/internal/str_format/arg.cc
parentc44657f55692eddf5504156645d1f4ec7b3acabd (diff)
Export of internal Abseil changes
--
97faa5fdfa4cd5d7a74cd9332cddd8a7c1e67b89 by Abseil Team <absl-team@google.com>:

Internal changes

PiperOrigin-RevId: 295164378

--
74990f100b3f4172c770ef8c76c05c8e99febdde by Xiaoyi Zhang <zhangxy@google.com>:

Release `absl::Cord`.

PiperOrigin-RevId: 295161959

--
6018c57f43c45c31dc1a61c0cd75fa2aa9be8dab by Gennadiy Rozental <rogeeff@google.com>:

Introduce independent notion of FlagStaticTypeID.

This change separates static flag value type identification from the type specific "vtable" with all the operations specific to value type. This change allows us to do the following:
* We can move most of "vtable" implementation from handle header, which will become public soon, into implementation details of Abseil Flag.
* We can combine back marshalling ops and general ops into a single vtable routine. They were split previously to facilitate type identification without requiring marshalling routines to be exposed in header.
* We do not need to store two vtable pointers. We can now store only one. The static type id can be deduced on request.

Overall we are saving 24 bytes per flag according to size_tester run.

PiperOrigin-RevId: 295149687

--
986b78e9ba571aa85154e70bda4580edd45bb7bf by Abseil Team <absl-team@google.com>:

Update internal comments.

PiperOrigin-RevId: 295030681

--
825412b29fd6015027bbc3e5f802706eee0d2837 by Matthew Brown <matthewbr@google.com>:

Change str_format_internal::ConversionChar to an enum (from a struct-wrapped enum).

PiperOrigin-RevId: 294987462

--
f9f88d91809d2cc33fc129df70fa93e7a2c35c69 by Derek Mauro <dmauro@google.com>:

Use more precise wording in the question on live-at-head

PiperOrigin-RevId: 294957679
GitOrigin-RevId: 97faa5fdfa4cd5d7a74cd9332cddd8a7c1e67b89
Change-Id: I081e70d148ffac7296d65e2a2f775f643eaf70bf
Diffstat (limited to 'absl/strings/internal/str_format/arg.cc')
-rw-r--r--absl/strings/internal/str_format/arg.cc37
1 files changed, 17 insertions, 20 deletions
diff --git a/absl/strings/internal/str_format/arg.cc b/absl/strings/internal/str_format/arg.cc
index d3904124a1a9..4d0604e00c4b 100644
--- a/absl/strings/internal/str_format/arg.cc
+++ b/absl/strings/internal/str_format/arg.cc
@@ -88,7 +88,7 @@ class ConvertedIntInfo {
   template <typename T>
   void UnsignedToStringRight(T u, ConversionChar conv) {
     char *p = end();
-    switch (conv.radix()) {
+    switch (FormatConversionCharRadix(conv)) {
       default:
       case 10:
         for (; u; u /= 10)
@@ -99,7 +99,7 @@ class ConvertedIntInfo {
           *--p = static_cast<char>('0' + static_cast<size_t>(u % 8));
         break;
       case 16: {
-        const char *digits = kDigit[conv.upper() ? 1 : 0];
+        const char *digits = kDigit[FormatConversionCharIsUpper(conv) ? 1 : 0];
         for (; u; u /= 16) *--p = digits[static_cast<size_t>(u % 16)];
         break;
       }
@@ -121,21 +121,20 @@ class ConvertedIntInfo {
 string_view BaseIndicator(const ConvertedIntInfo &info,
                           const ConversionSpec conv) {
   bool alt = conv.flags().alt;
-  int radix = conv.conv().radix();
-  if (conv.conv().id() == ConversionChar::p)
-    alt = true;  // always show 0x for %p.
+  int radix = FormatConversionCharRadix(conv.conv());
+  if (conv.conv() == ConversionChar::p) alt = true;  // always show 0x for %p.
   // From the POSIX description of '#' flag:
   //   "For x or X conversion specifiers, a non-zero result shall have
   //   0x (or 0X) prefixed to it."
   if (alt && radix == 16 && !info.digits().empty()) {
-    if (conv.conv().upper()) return "0X";
+    if (FormatConversionCharIsUpper(conv.conv())) return "0X";
     return "0x";
   }
   return {};
 }
 
 string_view SignColumn(bool neg, const ConversionSpec conv) {
-  if (conv.conv().is_signed()) {
+  if (FormatConversionCharIsSigned(conv.conv())) {
     if (neg) return "-";
     if (conv.flags().show_pos) return "+";
     if (conv.flags().sign_col) return " ";
@@ -175,7 +174,7 @@ bool ConvertIntImplInner(const ConvertedIntInfo &info,
   if (!precision_specified)
     precision = 1;
 
-  if (conv.flags().alt && conv.conv().id() == ConversionChar::o) {
+  if (conv.flags().alt && conv.conv() == ConversionChar::o) {
     // From POSIX description of the '#' (alt) flag:
     //   "For o conversion, it increases the precision (if necessary) to
     //   force the first digit of the result to be zero."
@@ -211,7 +210,7 @@ bool ConvertIntImplInner(const ConvertedIntInfo &info,
 template <typename T>
 bool ConvertIntImplInner(T v, const ConversionSpec conv, FormatSinkImpl *sink) {
   ConvertedIntInfo info(v, conv.conv());
-  if (conv.flags().basic && conv.conv().id() != ConversionChar::p) {
+  if (conv.flags().basic && (conv.conv() != ConversionChar::p)) {
     if (info.is_neg()) sink->Append(1, '-');
     if (info.digits().empty()) {
       sink->Append(1, '0');
@@ -225,14 +224,13 @@ bool ConvertIntImplInner(T v, const ConversionSpec conv, FormatSinkImpl *sink) {
 
 template <typename T>
 bool ConvertIntArg(T v, const ConversionSpec conv, FormatSinkImpl *sink) {
-  if (conv.conv().is_float()) {
+  if (FormatConversionCharIsFloat(conv.conv())) {
     return FormatConvertImpl(static_cast<double>(v), conv, sink).value;
   }
-  if (conv.conv().id() == ConversionChar::c)
+  if (conv.conv() == ConversionChar::c)
     return ConvertCharImpl(static_cast<unsigned char>(v), conv, sink);
-  if (!conv.conv().is_integral())
-    return false;
-  if (!conv.conv().is_signed() && IsSigned<T>::value) {
+  if (!FormatConversionCharIsIntegral(conv.conv())) return false;
+  if (!FormatConversionCharIsSigned(conv.conv()) && IsSigned<T>::value) {
     using U = typename MakeUnsigned<T>::type;
     return FormatConvertImpl(static_cast<U>(v), conv, sink).value;
   }
@@ -241,13 +239,13 @@ bool ConvertIntArg(T v, const ConversionSpec conv, FormatSinkImpl *sink) {
 
 template <typename T>
 bool ConvertFloatArg(T v, const ConversionSpec conv, FormatSinkImpl *sink) {
-  return conv.conv().is_float() && ConvertFloatImpl(v, conv, sink);
+  return FormatConversionCharIsFloat(conv.conv()) &&
+         ConvertFloatImpl(v, conv, sink);
 }
 
 inline bool ConvertStringArg(string_view v, const ConversionSpec conv,
                              FormatSinkImpl *sink) {
-  if (conv.conv().id() != ConversionChar::s)
-    return false;
+  if (conv.conv() != ConversionChar::s) return false;
   if (conv.flags().basic) {
     sink->Append(v);
     return true;
@@ -274,7 +272,7 @@ ConvertResult<Conv::s> FormatConvertImpl(string_view v,
 ConvertResult<Conv::s | Conv::p> FormatConvertImpl(const char *v,
                                                    const ConversionSpec conv,
                                                    FormatSinkImpl *sink) {
-  if (conv.conv().id() == ConversionChar::p)
+  if (conv.conv() == ConversionChar::p)
     return {FormatConvertImpl(VoidPtr(v), conv, sink).value};
   size_t len;
   if (v == nullptr) {
@@ -291,8 +289,7 @@ ConvertResult<Conv::s | Conv::p> FormatConvertImpl(const char *v,
 // ==================== Raw pointers ====================
 ConvertResult<Conv::p> FormatConvertImpl(VoidPtr v, const ConversionSpec conv,
                                          FormatSinkImpl *sink) {
-  if (conv.conv().id() != ConversionChar::p)
-    return {false};
+  if (conv.conv() != ConversionChar::p) return {false};
   if (!v.value) {
     sink->Append("(nil)");
     return {true};