You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/04/25 23:32:08 UTC
[15/50] mesos git commit: Avoid construction of temporary strings in
`NumberWriter` for doubles.
Avoid construction of temporary strings in `NumberWriter` for doubles.
With this + https://reviews.apache.org/r/43024/, the number of calls to
`operator new` and `operator delete` were reduced by roughly 1/3.
Review: https://reviews.apache.org/r/43023/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cb46ff68
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cb46ff68
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cb46ff68
Branch: refs/heads/0.26.x
Commit: cb46ff68142ad3345aec4ffbfc9f964063f65aa8
Parents: c751d89
Author: Michael Park <mp...@apache.org>
Authored: Sun Jan 31 20:37:42 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Fri Feb 26 20:59:05 2016 -0800
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/jsonify.hpp | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/cb46ff68/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
index 5e1df28..b273476 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
@@ -147,8 +147,8 @@ public:
// Prints a floating point value, with the specified precision, see:
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2005.pdf
// Additionally ensures that a decimal point is in the output.
- char buffer[50] = {}; // More than enough for the specified precision.
- snprintf(
+ char buffer[50]; // More than enough for the specified precision.
+ const int size = snprintf(
buffer,
sizeof(buffer),
"%#.*g",
@@ -157,10 +157,19 @@ public:
// Get rid of excess trailing zeroes before outputting.
// Otherwise, printing 1.0 would result in "1.00000000000000".
- std::string trimmed = strings::trim(buffer, strings::SUFFIX, "0");
+ //
+ // NOTE: We intentionally do not use `strings::trim` here in order to
+ // avoid construction of temporary strings.
+ int back = size - 1;
+ for (; back > 0; --back) {
+ if (buffer[back] != '0') {
+ break;
+ }
+ buffer[back] = '\0';
+ }
// NOTE: valid JSON numbers cannot end with a '.'.
- *stream_ << trimmed << (trimmed.back() == '.' ? "0" : "");
+ *stream_ << buffer << (buffer[back] == '.' ? "0" : "");
break;
}
}