Skip to content

Commit

Permalink
Auto-generate files after cl/702381123
Browse files Browse the repository at this point in the history
  • Loading branch information
protobuf-team-bot committed Dec 3, 2024
1 parent eb8a34d commit a014c7d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions php/ext/google/protobuf/php-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3844,7 +3844,7 @@ static bool _upb_mapsorter_resize(_upb_mapsorter* s, _upb_sortedmap* sorted,

if (sorted->end > s->cap) {
const int oldsize = s->cap * sizeof(*s->entries);
s->cap = upb_Log2CeilingSize(sorted->end);
s->cap = upb_RoundUpToPowerOfTwo(sorted->end);
const int newsize = s->cap * sizeof(*s->entries);
s->entries = upb_grealloc(s->entries, oldsize, newsize);
if (!s->entries) return false;
Expand Down Expand Up @@ -12455,7 +12455,7 @@ bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg,
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
if (!in) {
// No internal data, allocate from scratch.
size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead));
size_t size = UPB_MAX(128, upb_RoundUpToPowerOfTwo(need + overhead));
in = upb_Arena_Malloc(a, size);
if (!in) return false;

Expand All @@ -12465,7 +12465,7 @@ bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg,
UPB_PRIVATE(_upb_Message_SetInternal)(msg, in);
} else if (in->ext_begin - in->unknown_end < need) {
// Internal data is too small, reallocate.
size_t new_size = upb_Log2CeilingSize(in->size + need);
size_t new_size = upb_RoundUpToPowerOfTwo(in->size + need);
size_t ext_bytes = in->size - in->ext_begin;
size_t new_ext_begin = new_size - ext_bytes;
in = upb_Arena_Realloc(a, in, in->size, new_size);
Expand Down Expand Up @@ -15783,7 +15783,7 @@ upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx,
upb_StringView key) {
size_t need = key.size + sizeof(void*);
if (ctx->tmp_buf_size < need) {
ctx->tmp_buf_size = UPB_MAX(64, upb_Log2Ceiling(need));
ctx->tmp_buf_size = UPB_MAX(64, upb_RoundUpToPowerOfTwo(need));
ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size);
if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx);
}
Expand Down
4 changes: 3 additions & 1 deletion php/ext/google/protobuf/php-upb.h
Original file line number Diff line number Diff line change
Expand Up @@ -13885,7 +13885,9 @@ UPB_INLINE int upb_Log2Ceiling(int x) {
#endif
}

UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); }
UPB_INLINE int upb_RoundUpToPowerOfTwo(int x) {
return 1 << upb_Log2Ceiling(x);
}

#ifdef __cplusplus
} /* extern "C" */
Expand Down
8 changes: 4 additions & 4 deletions ruby/ext/google/protobuf_c/ruby-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3844,7 +3844,7 @@ static bool _upb_mapsorter_resize(_upb_mapsorter* s, _upb_sortedmap* sorted,

if (sorted->end > s->cap) {
const int oldsize = s->cap * sizeof(*s->entries);
s->cap = upb_Log2CeilingSize(sorted->end);
s->cap = upb_RoundUpToPowerOfTwo(sorted->end);
const int newsize = s->cap * sizeof(*s->entries);
s->entries = upb_grealloc(s->entries, oldsize, newsize);
if (!s->entries) return false;
Expand Down Expand Up @@ -11942,7 +11942,7 @@ bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg,
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
if (!in) {
// No internal data, allocate from scratch.
size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead));
size_t size = UPB_MAX(128, upb_RoundUpToPowerOfTwo(need + overhead));
in = upb_Arena_Malloc(a, size);
if (!in) return false;

Expand All @@ -11952,7 +11952,7 @@ bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg,
UPB_PRIVATE(_upb_Message_SetInternal)(msg, in);
} else if (in->ext_begin - in->unknown_end < need) {
// Internal data is too small, reallocate.
size_t new_size = upb_Log2CeilingSize(in->size + need);
size_t new_size = upb_RoundUpToPowerOfTwo(in->size + need);
size_t ext_bytes = in->size - in->ext_begin;
size_t new_ext_begin = new_size - ext_bytes;
in = upb_Arena_Realloc(a, in, in->size, new_size);
Expand Down Expand Up @@ -15270,7 +15270,7 @@ upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx,
upb_StringView key) {
size_t need = key.size + sizeof(void*);
if (ctx->tmp_buf_size < need) {
ctx->tmp_buf_size = UPB_MAX(64, upb_Log2Ceiling(need));
ctx->tmp_buf_size = UPB_MAX(64, upb_RoundUpToPowerOfTwo(need));
ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size);
if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx);
}
Expand Down
4 changes: 3 additions & 1 deletion ruby/ext/google/protobuf_c/ruby-upb.h
Original file line number Diff line number Diff line change
Expand Up @@ -13887,7 +13887,9 @@ UPB_INLINE int upb_Log2Ceiling(int x) {
#endif
}

UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); }
UPB_INLINE int upb_RoundUpToPowerOfTwo(int x) {
return 1 << upb_Log2Ceiling(x);
}

#ifdef __cplusplus
} /* extern "C" */
Expand Down

0 comments on commit a014c7d

Please sign in to comment.