From d51df2d2d7f555f4a9cfa606408f32b85c3cec37 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Fri, 29 Mar 2024 11:56:20 -0700 Subject: [PATCH] upb: make upb_Array_Reserve() a public function PiperOrigin-RevId: 620303837 --- upb/message/array.h | 4 ++++ upb/message/internal/array.h | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/upb/message/array.h b/upb/message/array.h index 8869b30a45..cbe37698eb 100644 --- a/upb/message/array.h +++ b/upb/message/array.h @@ -63,6 +63,10 @@ UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, // REQUIRES: `i + count <= upb_Array_Size(arr)` UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); +// Reserves |size| elements of storage for the array. +UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size, + upb_Arena* arena); + // Changes the size of a vector. New elements are initialized to NULL/0. // Returns false on allocation failure. UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); diff --git a/upb/message/internal/array.h b/upb/message/internal/array.h index 0414432a95..704bf729e2 100644 --- a/upb/message/internal/array.h +++ b/upb/message/internal/array.h @@ -94,8 +94,8 @@ UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, upb_Arena* arena); -UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, - size_t size, upb_Arena* arena) { +UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size, + upb_Arena* arena) { UPB_ASSERT(!upb_Array_IsFrozen(array)); if (array->UPB_PRIVATE(capacity) < size) return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); @@ -108,7 +108,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Array_ResizeUninitialized)( UPB_ASSERT(!upb_Array_IsFrozen(array)); UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || arena); // Allow NULL arena when shrinking. - if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; + if (!upb_Array_Reserve(array, size, arena)) return false; array->UPB_ONLYBITS(size) = size; return true; }