Unverified Commit 7f07bcdc authored by Hao Nguyen's avatar Hao Nguyen Committed by GitHub

Merge pull request #6072 from haon4/revert_strcat

Partially Revert "Replaced all instances of Simple{IDF}toa with StrCat."
parents 6b4b9869 ded3c23e
...@@ -643,7 +643,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) { ...@@ -643,7 +643,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) {
} else if (value != value) { } else if (value != value) {
return "std::numeric_limits<double>::quiet_NaN()"; return "std::numeric_limits<double>::quiet_NaN()";
} else { } else {
return StrCat(value); return SimpleDtoa(value);
} }
} }
case FieldDescriptor::CPPTYPE_FLOAT: { case FieldDescriptor::CPPTYPE_FLOAT: {
...@@ -655,7 +655,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) { ...@@ -655,7 +655,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) {
} else if (value != value) { } else if (value != value) {
return "std::numeric_limits<float>::quiet_NaN()"; return "std::numeric_limits<float>::quiet_NaN()";
} else { } else {
std::string float_value = StrCat(value); std::string float_value = SimpleFtoa(value);
// If floating point value contains a period (.) or an exponent // If floating point value contains a period (.) or an exponent
// (either E or e), then append suffix 'f' to make it a float // (either E or e), then append suffix 'f' to make it a float
// literal. // literal.
......
...@@ -325,7 +325,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) ...@@ -325,7 +325,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
} else if (std::isnan(value)) { } else if (std::isnan(value)) {
return "double.NaN"; return "double.NaN";
} }
return StrCat(value) + "D"; return SimpleDtoa(value) + "D";
} }
case FieldDescriptor::TYPE_FLOAT: { case FieldDescriptor::TYPE_FLOAT: {
float value = descriptor->default_value_float(); float value = descriptor->default_value_float();
...@@ -336,7 +336,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) ...@@ -336,7 +336,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
} else if (std::isnan(value)) { } else if (std::isnan(value)) {
return "float.NaN"; return "float.NaN";
} }
return StrCat(value) + "F"; return SimpleFtoa(value) + "F";
} }
case FieldDescriptor::TYPE_INT64: case FieldDescriptor::TYPE_INT64:
return StrCat(descriptor->default_value_int64()) + "L"; return StrCat(descriptor->default_value_int64()) + "L";
......
...@@ -522,7 +522,7 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable, ...@@ -522,7 +522,7 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable,
} else if (value != value) { } else if (value != value) {
return "Double.NaN"; return "Double.NaN";
} else { } else {
return StrCat(value) + "D"; return SimpleDtoa(value) + "D";
} }
} }
case FieldDescriptor::CPPTYPE_FLOAT: { case FieldDescriptor::CPPTYPE_FLOAT: {
...@@ -534,7 +534,7 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable, ...@@ -534,7 +534,7 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable,
} else if (value != value) { } else if (value != value) {
return "Float.NaN"; return "Float.NaN";
} else { } else {
return StrCat(value) + "F"; return SimpleFtoa(value) + "F";
} }
} }
case FieldDescriptor::CPPTYPE_BOOL: case FieldDescriptor::CPPTYPE_BOOL:
......
...@@ -733,9 +733,9 @@ std::string EscapeBase64(const std::string& in) { ...@@ -733,9 +733,9 @@ std::string EscapeBase64(const std::string& in) {
return result; return result;
} }
// Post-process the result of StrCat to *exactly* match the original codegen's // Post-process the result of SimpleFtoa/SimpleDtoa to *exactly* match the
// formatting (which is just .toString() on java.lang.Double or // original codegen's formatting (which is just .toString() on java.lang.Double
// java.lang.Float). // or java.lang.Float).
std::string PostProcessFloat(std::string result) { std::string PostProcessFloat(std::string result) {
// If inf, -inf or nan, replace with +Infinity, -Infinity or NaN. // If inf, -inf or nan, replace with +Infinity, -Infinity or NaN.
if (result == "inf") { if (result == "inf") {
...@@ -787,12 +787,12 @@ std::string PostProcessFloat(std::string result) { ...@@ -787,12 +787,12 @@ std::string PostProcessFloat(std::string result) {
} }
std::string FloatToString(float value) { std::string FloatToString(float value) {
std::string result = StrCat(value); std::string result = SimpleFtoa(value);
return PostProcessFloat(result); return PostProcessFloat(result);
} }
std::string DoubleToString(double value) { std::string DoubleToString(double value) {
std::string result = StrCat(value); std::string result = SimpleDtoa(value);
return PostProcessFloat(result); return PostProcessFloat(result);
} }
......
...@@ -818,10 +818,10 @@ string DefaultValue(const FieldDescriptor* field) { ...@@ -818,10 +818,10 @@ string DefaultValue(const FieldDescriptor* field) {
return StrCat(field->default_value_uint64()) + "ULL"; return StrCat(field->default_value_uint64()) + "ULL";
case FieldDescriptor::CPPTYPE_DOUBLE: case FieldDescriptor::CPPTYPE_DOUBLE:
return HandleExtremeFloatingPoint( return HandleExtremeFloatingPoint(
StrCat(field->default_value_double()), false); SimpleDtoa(field->default_value_double()), false);
case FieldDescriptor::CPPTYPE_FLOAT: case FieldDescriptor::CPPTYPE_FLOAT:
return HandleExtremeFloatingPoint( return HandleExtremeFloatingPoint(
StrCat(field->default_value_float()), true); SimpleFtoa(field->default_value_float()), true);
case FieldDescriptor::CPPTYPE_BOOL: case FieldDescriptor::CPPTYPE_BOOL:
return field->default_value_bool() ? "YES" : "NO"; return field->default_value_bool() ? "YES" : "NO";
case FieldDescriptor::CPPTYPE_STRING: { case FieldDescriptor::CPPTYPE_STRING: {
......
...@@ -1267,7 +1267,7 @@ bool Parser::ParseDefaultAssignment( ...@@ -1267,7 +1267,7 @@ bool Parser::ParseDefaultAssignment(
double value; double value;
DO(ConsumeNumber(&value, "Expected number.")); DO(ConsumeNumber(&value, "Expected number."));
// And stringify it again. // And stringify it again.
default_value->append(StrCat(value)); default_value->append(SimpleDtoa(value));
break; break;
case FieldDescriptorProto::TYPE_BOOL: case FieldDescriptorProto::TYPE_BOOL:
......
...@@ -250,7 +250,7 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) { ...@@ -250,7 +250,7 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) {
// infinity * 0 = nan // infinity * 0 = nan
return "(1e10000 * 0)"; return "(1e10000 * 0)";
} else { } else {
return "float(" + StrCat(value) + ")"; return "float(" + SimpleDtoa(value) + ")";
} }
} }
case FieldDescriptor::CPPTYPE_FLOAT: { case FieldDescriptor::CPPTYPE_FLOAT: {
...@@ -266,7 +266,7 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) { ...@@ -266,7 +266,7 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) {
// infinity - infinity = nan // infinity - infinity = nan
return "(1e10000 * 0)"; return "(1e10000 * 0)";
} else { } else {
return "float(" + StrCat(value) + ")"; return "float(" + SimpleFtoa(value) + ")";
} }
} }
case FieldDescriptor::CPPTYPE_BOOL: case FieldDescriptor::CPPTYPE_BOOL:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment