upb: move ElemSizeLg2() from message/ into mini_table/

PiperOrigin-RevId: 584380544
diff --git a/upb/message/BUILD b/upb/message/BUILD
index 05fa825..9ec46bd 100644
--- a/upb/message/BUILD
+++ b/upb/message/BUILD
@@ -107,7 +107,6 @@
         "internal/map_entry.h",
         "internal/map_sorter.h",
         "internal/message.h",
-        "internal/size_log2.h",
         "map_gencode_util.h",
     ],
     copts = UPB_DEFAULT_COPTS,
@@ -121,6 +120,7 @@
         "//upb:hash",
         "//upb:mem",
         "//upb:mini_table",
+        "//upb:mini_table_internal",
         "//upb:port",
     ],
 )
diff --git a/upb/message/accessors.h b/upb/message/accessors.h
index 3cc1e07..7e6f817 100644
--- a/upb/message/accessors.h
+++ b/upb/message/accessors.h
@@ -27,6 +27,7 @@
 #include "upb/mini_table/enum.h"
 #include "upb/mini_table/extension.h"
 #include "upb/mini_table/field.h"
+#include "upb/mini_table/internal/field.h"
 
 // Must be last.
 #include "upb/mini_table/internal/field.h"
@@ -378,7 +379,7 @@
   _upb_MiniTableField_CheckIsArray(field);
   upb_Array* array = upb_Message_GetMutableArray(msg, field);
   if (!array) {
-    array = _upb_Array_New(arena, 4, _upb_MiniTable_ElementSizeLg2(field));
+    array = _upb_Array_New(arena, 4, _upb_MiniTableField_ElemSizeLg2(field));
     // Check again due to: https://godbolt.org/z/7WfaoKG1r
     _upb_MiniTableField_CheckIsArray(field);
     upb_MessageValue val;
diff --git a/upb/message/array.c b/upb/message/array.c
index 7c28d0b..40264ea 100644
--- a/upb/message/array.c
+++ b/upb/message/array.c
@@ -13,13 +13,13 @@
 #include "upb/base/descriptor_constants.h"
 #include "upb/mem/arena.h"
 #include "upb/message/internal/array.h"
-#include "upb/message/internal/size_log2.h"
+#include "upb/mini_table/internal/size_log2.h"
 
 // Must be last.
 #include "upb/port/def.inc"
 
 upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) {
-  return _upb_Array_New(a, 4, upb_SizeLog2_CType(type));
+  return _upb_Array_New(a, 4, upb_CType_SizeLg2(type));
 }
 
 const void* upb_Array_DataPtr(const upb_Array* arr) {
diff --git a/upb/message/copy.c b/upb/message/copy.c
index 23f558f..62e8aa8 100644
--- a/upb/message/copy.c
+++ b/upb/message/copy.c
@@ -20,7 +20,6 @@
 #include "upb/message/internal/extension.h"
 #include "upb/message/internal/map.h"
 #include "upb/message/internal/message.h"
-#include "upb/message/internal/size_log2.h"
 #include "upb/message/map.h"
 #include "upb/message/message.h"
 #include "upb/message/tagged_ptr.h"
@@ -28,6 +27,7 @@
 #include "upb/mini_table/field.h"
 #include "upb/mini_table/internal/field.h"
 #include "upb/mini_table/internal/message.h"
+#include "upb/mini_table/internal/size_log2.h"
 #include "upb/mini_table/message.h"
 
 // Must be last.
@@ -143,7 +143,7 @@
                                const upb_MiniTable* sub, upb_Arena* arena) {
   size_t size = array->size;
   upb_Array* cloned_array =
-      _upb_Array_New(arena, size, upb_SizeLog2_CType(value_type));
+      _upb_Array_New(arena, size, upb_CType_SizeLg2(value_type));
   if (!cloned_array) {
     return NULL;
   }
diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h
index 7b28b49..5ace3fc 100644
--- a/upb/message/internal/accessors.h
+++ b/upb/message/internal/accessors.h
@@ -12,14 +12,12 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "upb/base/descriptor_constants.h"
 #include "upb/base/string_view.h"
 #include "upb/mem/arena.h"
 #include "upb/message/array.h"
 #include "upb/message/internal/extension.h"
 #include "upb/message/internal/map.h"
 #include "upb/message/internal/message.h"
-#include "upb/message/internal/size_log2.h"
 #include "upb/message/internal/types.h"
 #include "upb/message/map.h"
 #include "upb/message/message.h"
@@ -185,12 +183,6 @@
   UPB_UNREACHABLE();
 }
 
-UPB_INLINE size_t
-_upb_MiniTable_ElementSizeLg2(const upb_MiniTableField* field) {
-  return upb_SizeLog2_FieldType(
-      (upb_FieldType)field->UPB_PRIVATE(descriptortype));
-}
-
 // Here we define universal getter/setter functions for message fields.
 // These look very branchy and inefficient, but as long as the MiniTableField
 // values are known at compile time, all the branches are optimized away and
diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD
index f4b2ffe..58c4b23 100644
--- a/upb/mini_table/BUILD
+++ b/upb/mini_table/BUILD
@@ -66,6 +66,7 @@
         "internal/field.h",
         "internal/file.h",
         "internal/message.h",
+        "internal/size_log2.h",
         "internal/sub.h",
     ],
     visibility = ["//visibility:public"],
diff --git a/upb/mini_table/internal/field.h b/upb/mini_table/internal/field.h
index 7425d71..4dda1a6 100644
--- a/upb/mini_table/internal/field.h
+++ b/upb/mini_table/internal/field.h
@@ -8,9 +8,11 @@
 #ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_
 #define UPB_MINI_TABLE_INTERNAL_FIELD_H_
 
+#include <stddef.h>
 #include <stdint.h>
 
 #include "upb/base/descriptor_constants.h"
+#include "upb/mini_table/internal/size_log2.h"
 
 // Must be last.
 #include "upb/port/def.inc"
@@ -95,6 +97,12 @@
   UPB_ASSUME(field->presence == 0);
 }
 
+UPB_INLINE size_t
+_upb_MiniTableField_ElemSizeLg2(const struct upb_MiniTableField* field) {
+  return upb_FieldType_SizeLg2(
+      (upb_FieldType)field->UPB_PRIVATE(descriptortype));
+}
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/upb/message/internal/size_log2.h b/upb/mini_table/internal/size_log2.h
similarity index 89%
rename from upb/message/internal/size_log2.h
rename to upb/mini_table/internal/size_log2.h
index c263012..f8fcea8 100644
--- a/upb/message/internal/size_log2.h
+++ b/upb/mini_table/internal/size_log2.h
@@ -6,8 +6,8 @@
 // license that can be found in the LICENSE file or at
 // https://developers.google.com/open-source/licenses/bsd
 
-#ifndef UPB_MESSAGE_INTERNAL_SIZE_LOG2_H_
-#define UPB_MESSAGE_INTERNAL_SIZE_LOG2_H_
+#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_
+#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_
 
 #include <stddef.h>
 #include <stdint.h>
@@ -22,7 +22,7 @@
 #endif
 
 // Return the log2 of the storage size in bytes for a upb_CType
-UPB_INLINE int upb_SizeLog2_CType(upb_CType c_type) {
+UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) {
   static const int8_t size[] = {
       0,               // kUpb_CType_Bool
       2,               // kUpb_CType_Float
@@ -42,7 +42,7 @@
 }
 
 // Return the log2 of the storage size in bytes for a upb_FieldType
-UPB_INLINE int upb_SizeLog2_FieldType(upb_FieldType field_type) {
+UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) {
   static const int8_t size[] = {
       3,               // kUpb_FieldType_Double
       2,               // kUpb_FieldType_Float
@@ -74,4 +74,4 @@
 
 #include "upb/port/undef.inc"
 
-#endif /* UPB_MESSAGE_INTERNAL_SIZE_LOG2_H_ */
+#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */
diff --git a/upb/wire/decode.c b/upb/wire/decode.c
index 9572766..f33ed06 100644
--- a/upb/wire/decode.c
+++ b/upb/wire/decode.c
@@ -25,7 +25,6 @@
 #include "upb/message/internal/map.h"
 #include "upb/message/internal/map_entry.h"
 #include "upb/message/internal/message.h"
-#include "upb/message/internal/size_log2.h"
 #include "upb/message/map.h"
 #include "upb/message/message.h"
 #include "upb/message/tagged_ptr.h"
@@ -35,6 +34,7 @@
 #include "upb/mini_table/field.h"
 #include "upb/mini_table/internal/field.h"
 #include "upb/mini_table/internal/message.h"
+#include "upb/mini_table/internal/size_log2.h"
 #include "upb/mini_table/message.h"
 #include "upb/mini_table/sub.h"
 #include "upb/port/atomic.h"
@@ -476,7 +476,7 @@
 upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d,
                                     const upb_MiniTableField* field) {
   const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype);
-  const size_t lg2 = upb_SizeLog2_FieldType(field_type);
+  const size_t lg2 = upb_FieldType_SizeLg2(field_type);
   upb_Array* ret = _upb_Array_New(&d->arena, 4, lg2);
   if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
   return ret;