Change `google::protobuf::MapKey::GetStringValue` to return `absl::string_view`

PiperOrigin-RevId: 674294662
diff --git a/src/google/protobuf/map_field.cc b/src/google/protobuf/map_field.cc
index 19cc3b7..dccef67 100644
--- a/src/google/protobuf/map_field.cc
+++ b/src/google/protobuf/map_field.cc
@@ -8,6 +8,7 @@
 #include "google/protobuf/map_field.h"
 
 #include <atomic>
+#include <string>
 #include <utility>
 #include <vector>
 
@@ -243,7 +244,8 @@
     const MapKey& map_key = it.GetKey();
     switch (key_des->cpp_type()) {
       case FieldDescriptor::CPPTYPE_STRING:
-        reflection->SetString(new_entry, key_des, map_key.GetStringValue());
+        reflection->SetString(new_entry, key_des,
+                              std::string(map_key.GetStringValue()));
         break;
       case FieldDescriptor::CPPTYPE_INT64:
         reflection->SetInt64(new_entry, key_des, map_key.GetInt64Value());
diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h
index 2102156..c400700 100644
--- a/src/google/protobuf/map_field.h
+++ b/src/google/protobuf/map_field.h
@@ -18,6 +18,7 @@
 
 #include "absl/log/absl_check.h"
 #include "absl/log/absl_log.h"
+#include "absl/strings/string_view.h"
 #include "absl/synchronization/mutex.h"
 #include "google/protobuf/arena.h"
 #include "google/protobuf/descriptor.h"
@@ -136,7 +137,7 @@
     TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, "MapKey::GetBoolValue");
     return val_.bool_value;
   }
-  const std::string& GetStringValue() const {
+  absl::string_view GetStringValue() const {
     TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, "MapKey::GetStringValue");
     return val_.string_value.get();
   }
diff --git a/src/google/protobuf/map_field_inl.h b/src/google/protobuf/map_field_inl.h
index e6a7acf..5dfed43 100644
--- a/src/google/protobuf/map_field_inl.h
+++ b/src/google/protobuf/map_field_inl.h
@@ -16,6 +16,7 @@
 #include <type_traits>
 
 #include "absl/base/casts.h"
+#include "absl/strings/string_view.h"
 #include "google/protobuf/map.h"
 #include "google/protobuf/map_field.h"
 #include "google/protobuf/map_type_handler.h"
@@ -50,8 +51,8 @@
 inline bool UnwrapMapKeyImpl(const MapKey& map_key, const bool*) {
   return map_key.GetBoolValue();
 }
-inline const std::string& UnwrapMapKeyImpl(const MapKey& map_key,
-                                           const std::string*) {
+inline absl::string_view UnwrapMapKeyImpl(const MapKey& map_key,
+                                          const std::string*) {
   return map_key.GetStringValue();
 }
 inline const MapKey& UnwrapMapKeyImpl(const MapKey& map_key, const MapKey*) {
diff --git a/src/google/protobuf/reflection_visit_field_info.h b/src/google/protobuf/reflection_visit_field_info.h
index 148a246..c675827 100644
--- a/src/google/protobuf/reflection_visit_field_info.h
+++ b/src/google/protobuf/reflection_visit_field_info.h
@@ -1217,7 +1217,7 @@
 PROTOBUF_MAP_KEY_INFO(UInt32, uint32_t, UINT32);
 PROTOBUF_MAP_KEY_INFO(UInt64, uint64_t, UINT64);
 PROTOBUF_MAP_KEY_INFO(Bool, bool, BOOL);
-PROTOBUF_MAP_KEY_INFO(String, const std::string&, STRING);
+PROTOBUF_MAP_KEY_INFO(String, absl::string_view, STRING);
 
 #undef PROTOBUF_MAP_KEY_INFO
 
diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc
index 1ed6e57..b66195c 100644
--- a/src/google/protobuf/text_format.cc
+++ b/src/google/protobuf/text_format.cc
@@ -2566,7 +2566,8 @@
       ABSL_LOG(ERROR) << "Not supported.";
       break;
     case FieldDescriptor::CPPTYPE_STRING:
-      reflection->SetString(message, field_desc, key.GetStringValue());
+      reflection->SetString(message, field_desc,
+                            std::string(key.GetStringValue()));
       return;
     case FieldDescriptor::CPPTYPE_INT64:
       reflection->SetInt64(message, field_desc, key.GetInt64Value());