You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ne...@apache.org on 2017/04/10 20:04:37 UTC

[1/2] mesos git commit: Added stringify overload specialized for std::string.

Repository: mesos
Updated Branches:
  refs/heads/master 7ee317f8a -> d5c5bb0eb


Added stringify overload specialized for std::string.

In our code base 'stringify' serves as an explicitly named conversion
function to 'string'. The default implementation invokes a type's
'operator<<' to serialize the object to 'string' via a 'stringstream'
which is not a cheap operation.

This patch adds a trivial overload of 'stringify' for 'string' which
directly returns its argument. This helps us avoid the overhead of the
default overload. Calls of 'stringify' with 'string' argument might
appear in generic code, e.g., currently when invoking 'stringify' on a
container of 'string's.

Review: https://reviews.apache.org/r/58288/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/387ea0d5
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/387ea0d5
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/387ea0d5

Branch: refs/heads/master
Commit: 387ea0d57c1f261b918fc3578b860cd8128ba98e
Parents: 7ee317f
Author: Benjamin Bannier <be...@mesosphere.io>
Authored: Mon Apr 10 13:02:53 2017 -0700
Committer: Neil Conway <ne...@gmail.com>
Committed: Mon Apr 10 13:02:53 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/stringify.hpp | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/387ea0d5/3rdparty/stout/include/stout/stringify.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/stringify.hpp b/3rdparty/stout/include/stout/stringify.hpp
index 6984315..508cdc7 100644
--- a/3rdparty/stout/include/stout/stringify.hpp
+++ b/3rdparty/stout/include/stout/stringify.hpp
@@ -43,6 +43,16 @@ std::string stringify(T t)
   return out.str();
 }
 
+
+// We provide an explicit overload for strings so we do not incur the overhead
+// of a stringstream in generic code (e.g., when stringifying containers of
+// strings below).
+inline std::string stringify(const std::string& str)
+{
+  return str;
+}
+
+
 #ifdef __WINDOWS__
 inline std::string stringify(const std::wstring& str)
 {


[2/2] mesos git commit: Avoided excessive copying in the default implementation of 'stringify'.

Posted by ne...@apache.org.
Avoided excessive copying in the default implementation of 'stringify'.

The default implementation of 'stringify' was always making needless
copies of its argument which can be expensive for larger types. This
patch changes the default overload of 'stringify' to always take its
argument by const reference.

This change requires changing 'stringify' for 'bool' arguments from a
'stringify' template specialization to an overload.

Review: https://reviews.apache.org/r/58289/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d5c5bb0e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d5c5bb0e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d5c5bb0e

Branch: refs/heads/master
Commit: d5c5bb0ebfc1c5454d7b36c3a9dfc908e8f49eb7
Parents: 387ea0d
Author: Benjamin Bannier <be...@mesosphere.io>
Authored: Mon Apr 10 13:02:54 2017 -0700
Committer: Neil Conway <ne...@gmail.com>
Committed: Mon Apr 10 13:02:54 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/stringify.hpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d5c5bb0e/3rdparty/stout/include/stout/stringify.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/stringify.hpp b/3rdparty/stout/include/stout/stringify.hpp
index 508cdc7..44da506 100644
--- a/3rdparty/stout/include/stout/stringify.hpp
+++ b/3rdparty/stout/include/stout/stringify.hpp
@@ -33,7 +33,7 @@
 #include "set.hpp"
 
 template <typename T>
-std::string stringify(T t)
+std::string stringify(const T& t)
 {
   std::ostringstream out;
   out << t;
@@ -63,7 +63,6 @@ inline std::string stringify(const std::wstring& str)
 #endif // __WINDOWS__
 
 
-template <>
 inline std::string stringify(bool b)
 {
   return b ? "true" : "false";