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:35:59 UTC

[18/48] 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/c154d85e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c154d85e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c154d85e

Branch: refs/heads/0.27.x
Commit: c154d85e5408d6ae1fbdda1905815c304674ff17
Parents: b64851f
Author: Michael Park <mp...@apache.org>
Authored: Sun Jan 31 20:38:34 2016 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Feb 15 16:15:23 2016 -0500

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/protobuf.hpp      | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c154d85e/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;
       }
     }