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 <[email protected]>
Authored: Mon Apr 10 13:02:53 2017 -0700
Committer: Neil Conway <[email protected]>
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)
 {

Reply via email to