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:13 UTC

[2/2] mesos git commit: Avoid unnecessary string copies in `json` for protobuf messages.

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;
       }
     }