diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-07-18 07:44:19 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-07-18 09:04:18 +0200 |
commit | 7650449a6777710cf818d41862626164da0cd412 (patch) | |
tree | ddb32fd03bd9df82961ea176810b50faba133a23 /src/univalue | |
parent | e061e2778d592826970483e0844308c4e9a12626 (diff) |
univalue: Avoid unnecessary roundtrip through double for numbers
JSON makes no distinction between numbers and reals, and our code
doesn't need to do so either.
This removes VREAL, as well as its specific post-processing in
`UniValue::write`. Non-monetary amounts do not need to be forcibly
formatted with 8 decimals, so the extra roundtrip was unnecessary
(and potentially loses precision).
Diffstat (limited to 'src/univalue')
-rw-r--r-- | src/univalue/univalue.cpp | 5 | ||||
-rw-r--r-- | src/univalue/univalue.h | 3 | ||||
-rw-r--r-- | src/univalue/univalue_write.cpp | 7 |
3 files changed, 3 insertions, 12 deletions
diff --git a/src/univalue/univalue.cpp b/src/univalue/univalue.cpp index 6920c44c96..1d49a2cfc9 100644 --- a/src/univalue/univalue.cpp +++ b/src/univalue/univalue.cpp @@ -86,7 +86,7 @@ bool UniValue::setFloat(double val) oss << std::setprecision(16) << val; bool ret = setNumStr(oss.str()); - typ = VREAL; + typ = VNUM; return ret; } @@ -210,7 +210,6 @@ const char *uvTypeName(UniValue::VType t) case UniValue::VARR: return "array"; case UniValue::VSTR: return "string"; case UniValue::VNUM: return "number"; - case UniValue::VREAL: return "number"; } // not reached @@ -280,7 +279,7 @@ int64_t UniValue::get_int64() const double UniValue::get_real() const { - if (typ != VREAL && typ != VNUM) + if (typ != VNUM) throw std::runtime_error("JSON value is not a number as expected"); double retval; if (!ParseDouble(getValStr(), &retval)) diff --git a/src/univalue/univalue.h b/src/univalue/univalue.h index 54239741e2..4742b56f3d 100644 --- a/src/univalue/univalue.h +++ b/src/univalue/univalue.h @@ -16,7 +16,7 @@ class UniValue { public: - enum VType { VNULL, VOBJ, VARR, VSTR, VNUM, VREAL, VBOOL, }; + enum VType { VNULL, VOBJ, VARR, VSTR, VNUM, VBOOL, }; UniValue() { typ = VNULL; } UniValue(UniValue::VType initialType, const std::string& initialStr = "") { @@ -78,7 +78,6 @@ public: bool isBool() const { return (typ == VBOOL); } bool isStr() const { return (typ == VSTR); } bool isNum() const { return (typ == VNUM); } - bool isReal() const { return (typ == VREAL); } bool isArray() const { return (typ == VARR); } bool isObject() const { return (typ == VOBJ); } diff --git a/src/univalue/univalue_write.cpp b/src/univalue/univalue_write.cpp index d360c253b0..bce3997af7 100644 --- a/src/univalue/univalue_write.cpp +++ b/src/univalue/univalue_write.cpp @@ -61,13 +61,6 @@ string UniValue::write(unsigned int prettyIndent, case VSTR: s += "\"" + json_escape(val) + "\""; break; - case VREAL: - { - std::stringstream ss; - ss << std::showpoint << std::fixed << std::setprecision(8) << get_real(); - s += ss.str(); - } - break; case VNUM: s += val; break; |