Skip to content

Commit

Permalink
upb: make upb_Array_Reserve() a public function
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 620303837
  • Loading branch information
ericsalo authored and copybara-github committed Mar 29, 2024
1 parent 74ddc48 commit d51df2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions upb/message/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions upb/message/internal/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit d51df2d

Please sign in to comment.