Optimize `Reflection::ScratchSpace::CopyFromCord()`.

If the Cord is already flat, return a pointer to its data instead of copying
them to a string.

PiperOrigin-RevId: 610434454
pull/15905/head
Marcin Kowalczyk 9 months ago committed by Copybara-Service
parent 7ef3f87e3d
commit 03a472ea08
  1. 4
      src/google/protobuf/message.h

@ -101,6 +101,7 @@
#include "absl/memory/memory.h"
#include "absl/strings/cord.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "google/protobuf/arena.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/generated_message_reflection.h"
@ -601,6 +602,9 @@ class PROTOBUF_EXPORT Reflection final {
friend class Reflection;
absl::string_view CopyFromCord(const absl::Cord& cord) {
if (absl::optional<absl::string_view> flat = cord.TryFlat()) {
return *flat;
}
if (!buffer_) {
buffer_ = absl::make_unique<std::string>();
}

Loading…
Cancel
Save