upb: simplify upb_Map_Insert() down to upb_Map_Set() where possible

PiperOrigin-RevId: 592107014
diff --git a/upb/message/accessors.c b/upb/message/accessors.c
index edc63bc..0153956 100644
--- a/upb/message/accessors.c
+++ b/upb/message/accessors.c
@@ -21,11 +21,9 @@
 // Must be last.
 #include "upb/port/def.inc"
 
-upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map,
-                                               const upb_MiniTable* mini_table,
-                                               const upb_MiniTableField* f,
-                                               upb_Message* map_entry_message,
-                                               upb_Arena* arena) {
+bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table,
+                             const upb_MiniTableField* f,
+                             upb_Message* map_entry_message, upb_Arena* arena) {
   // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here.
   const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message(
       mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]);
@@ -43,7 +41,7 @@
       upb_Message_GetField(map_entry_message, map_entry_key_field, default_val);
   upb_MessageValue map_entry_value = upb_Message_GetField(
       map_entry_message, map_entry_value_field, default_val);
-  return upb_Map_Insert(map, map_entry_key, map_entry_value, arena);
+  return upb_Map_Set(map, map_entry_key, map_entry_value, arena);
 }
 
 bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2,
diff --git a/upb/message/accessors.h b/upb/message/accessors.h
index 55ce698..74d145c 100644
--- a/upb/message/accessors.h
+++ b/upb/message/accessors.h
@@ -449,11 +449,9 @@
 }
 
 // Updates a map entry given an entry message.
-upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map,
-                                               const upb_MiniTable* mini_table,
-                                               const upb_MiniTableField* field,
-                                               upb_Message* map_entry_message,
-                                               upb_Arena* arena);
+bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table,
+                             const upb_MiniTableField* field,
+                             upb_Message* map_entry_message, upb_Arena* arena);
 
 // Compares two messages by serializing them and calling memcmp().
 bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2,
diff --git a/upb/message/copy.c b/upb/message/copy.c
index 912be5b..c6def53 100644
--- a/upb/message/copy.c
+++ b/upb/message/copy.c
@@ -105,8 +105,7 @@
     if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) {
       return NULL;
     }
-    if (upb_Map_Insert(cloned_map, key, val, arena) ==
-        kUpb_MapInsertStatus_OutOfMemory) {
+    if (!upb_Map_Set(cloned_map, key, val, arena)) {
       return NULL;
     }
   }
diff --git a/upb/message/internal/map.h b/upb/message/internal/map.h
index dc4beae..51bc16b 100644
--- a/upb/message/internal/map.h
+++ b/upb/message/internal/map.h
@@ -7,9 +7,13 @@
 
 // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
 
-#ifndef UPB_COLLECTIONS_INTERNAL_MAP_H_
-#define UPB_COLLECTIONS_INTERNAL_MAP_H_
+#ifndef UPB_MESSAGE_INTERNAL_MAP_H_
+#define UPB_MESSAGE_INTERNAL_MAP_H_
 
+#include <stddef.h>
+#include <string.h>
+
+#include "upb/base/descriptor_constants.h"
 #include "upb/base/string_view.h"
 #include "upb/hash/str_table.h"
 #include "upb/mem/arena.h"
@@ -147,4 +151,4 @@
 
 #include "upb/port/undef.inc"
 
-#endif /* UPB_COLLECTIONS_INTERNAL_MAP_H_ */
+#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */
diff --git a/upb/message/internal/map_entry.h b/upb/message/internal/map_entry.h
index 956f00a..0c5c25e 100644
--- a/upb/message/internal/map_entry.h
+++ b/upb/message/internal/map_entry.h
@@ -5,8 +5,10 @@
 // license that can be found in the LICENSE file or at
 // https://developers.google.com/open-source/licenses/bsd
 
-#ifndef UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_
-#define UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_
+#ifndef UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_
+#define UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_
+
+#include <stdint.h>
 
 #include "upb/base/string_view.h"
 #include "upb/hash/common.h"
@@ -40,4 +42,4 @@
   upb_MapEntryData data;
 } upb_MapEntry;
 
-#endif  // UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_
+#endif  // UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_
diff --git a/upb/message/internal/map_sorter.h b/upb/message/internal/map_sorter.h
index a47d7a5..93be85e 100644
--- a/upb/message/internal/map_sorter.h
+++ b/upb/message/internal/map_sorter.h
@@ -7,8 +7,8 @@
 
 // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
 
-#ifndef UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_
-#define UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_
+#ifndef UPB_MESSAGE_INTERNAL_MAP_SORTER_H_
+#define UPB_MESSAGE_INTERNAL_MAP_SORTER_H_
 
 #include <stdlib.h>
 
@@ -86,4 +86,4 @@
 
 #include "upb/port/undef.inc"
 
-#endif /* UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ */
+#endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */
diff --git a/upb/message/promote.c b/upb/message/promote.c
index 329019e..4801c86 100644
--- a/upb/message/promote.c
+++ b/upb/message/promote.c
@@ -15,7 +15,6 @@
 #include "upb/mem/arena.h"
 #include "upb/message/accessors.h"
 #include "upb/message/array.h"
-#include "upb/message/internal/accessors.h"
 #include "upb/message/internal/array.h"
 #include "upb/message/internal/extension.h"
 #include "upb/message/internal/message.h"
@@ -347,13 +346,9 @@
     upb_Map* map = upb_Message_GetOrCreateMutableMap(msg, map_entry_mini_table,
                                                      field, arena);
     upb_Message* map_entry_message = ret.message;
-    upb_MapInsertStatus insert_status = upb_Message_InsertMapEntry(
-        map, mini_table, field, map_entry_message, arena);
-    if (insert_status == kUpb_MapInsertStatus_OutOfMemory) {
-      return kUpb_UnknownToMessage_OutOfMemory;
-    }
-    UPB_ASSUME(insert_status == kUpb_MapInsertStatus_Inserted ||
-               insert_status == kUpb_MapInsertStatus_Replaced);
+    bool insert_success = upb_Message_SetMapEntry(map, mini_table, field,
+                                                  map_entry_message, arena);
+    if (!insert_success) return kUpb_UnknownToMessage_OutOfMemory;
     upb_Message_DeleteUnknown(msg, unknown.ptr, unknown.len);
   }
   return kUpb_UnknownToMessage_Ok;