You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/02/01 06:22:12 UTC
[1/2] mesos git commit: Avoid construction of temporary strings in
`NumberWriter` for doubles.
Repository: mesos
Updated Branches:
refs/heads/master 8ca4efc15 -> 5e064503e
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/8daa9a5c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8daa9a5c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8daa9a5c
Branch: refs/heads/master
Commit: 8daa9a5c842a90b7b824a053c5f45897044de5fa
Parents: 8ca4efc
Author: Michael Park <mp...@apache.org>
Authored: Sun Jan 31 20:37:42 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Sun Jan 31 20:43:41 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/8daa9a5c/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 f9d7224..8220d00 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
@@ -148,8 +148,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",
@@ -158,10 +158,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;
}
}
[2/2] mesos git commit: Avoid unnecessary string copies in `json` for
protobuf messages.
Posted by mp...@apache.org.
Avoid unnecessary string copies in `json` for protobuf messages.
Review: https://reviews.apache.org/r/43024/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5e064503
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5e064503
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5e064503
Branch: refs/heads/master
Commit: 5e064503eb519aea3329f65f7ac93370b2910cc7
Parents: 8daa9a5
Author: Michael Park <mp...@apache.org>
Authored: Sun Jan 31 20:38:34 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Sun Jan 31 20:43:43 2016 -0800
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/protobuf.hpp | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/5e064503/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
index 6d7d033..eb5502c 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
@@ -696,12 +696,13 @@ inline void json(ObjectWriter* writer, const google::protobuf::Message& message)
reflection->GetRepeatedEnum(message, field, i)->name());
break;
case FieldDescriptor::CPPTYPE_STRING:
- std::string s =
- reflection->GetRepeatedString(message, field, i);
+ const std::string& s = reflection->GetRepeatedStringReference(
+ message, field, i, NULL);
if (field->type() == FieldDescriptor::TYPE_BYTES) {
- s = base64::encode(s);
+ writer->element(base64::encode(s));
+ } else {
+ writer->element(s);
}
- writer->element(s);
break;
}
}
@@ -737,11 +738,13 @@ inline void json(ObjectWriter* writer, const google::protobuf::Message& message)
field->name(), reflection->GetEnum(message, field)->name());
break;
case FieldDescriptor::CPPTYPE_STRING:
- std::string str = reflection->GetString(message, field);
+ const std::string& s = reflection->GetStringReference(
+ message, field, NULL);
if (field->type() == FieldDescriptor::TYPE_BYTES) {
- str = base64::encode(str);
+ writer->field(field->name(), base64::encode(s));
+ } else {
+ writer->field(field->name(), s);
}
- writer->field(field->name(), str);
break;
}
}