croslog: Update entire_line_ string for multiline entry

I added multiline log support on crrev.com/c/2507419, but that CL
didn't update entire_line_ string of entry for multiline entry.
This CL fixes that.

BUG=chromium:1144020
TEST=test passes

Change-Id: I046aeb2ddf80e69a008f0a5c1c40629e3ced43c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2550971
Commit-Queue: Yoshiki Iguchi <yoshiki@chromium.org>
Tested-by: Yoshiki Iguchi <yoshiki@chromium.org>
Auto-Submit: Yoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: Yuta Hijikata <ythjkt@chromium.org>
diff --git a/croslog/log_entry.cc b/croslog/log_entry.cc
index a20ea15..9a053fd 100644
--- a/croslog/log_entry.cc
+++ b/croslog/log_entry.cc
@@ -20,9 +20,23 @@
       entire_line_(std::move(entire_line)) {}
 
 void LogEntry::AppendLinesToMessage(const std::list<std::string>& lines) {
+  // Calculates the size of buffer to expand.
+  size_t lines_size = 0;
   for (const auto& line : lines) {
-    message_ += "\n";
-    message_ += line;
+    lines_size += line.size() + 1;
+  }
+
+  // Pre-reserves buffer for efficiency.
+  message_.reserve(message_.size() + lines_size);
+  entire_line_.reserve(entire_line_.size() + lines_size);
+
+  // Appends lines
+  for (const auto& line : lines) {
+    message_.append("\n", 1);
+    message_.append(line);
+
+    entire_line_.append("\n", 1);
+    entire_line_.append(line);
   }
 }
 
diff --git a/croslog/log_entry.h b/croslog/log_entry.h
index 465a5a0..9766e5b 100644
--- a/croslog/log_entry.h
+++ b/croslog/log_entry.h
@@ -45,7 +45,7 @@
   const std::string tag_;
   const int pid_;
   std::string message_;
-  const std::string entire_line_;
+  std::string entire_line_;
 };
 
 }  // namespace croslog