• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #include "upb/reflection/internal/desc_state.h"
9 
10 // Must be last.
11 #include "upb/port/def.inc"
12 
_upb_DescState_Grow(upb_DescState * d,upb_Arena * a)13 bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) {
14   const size_t oldbufsize = d->bufsize;
15   const int used = d->ptr - d->buf;
16 
17   if (!d->buf) {
18     d->buf = upb_Arena_Malloc(a, d->bufsize);
19     if (!d->buf) return false;
20     d->ptr = d->buf;
21     d->e.end = d->buf + d->bufsize;
22   }
23 
24   if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) {
25     d->bufsize *= 2;
26     d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize);
27     if (!d->buf) return false;
28     d->ptr = d->buf + used;
29     d->e.end = d->buf + d->bufsize;
30   }
31 
32   return true;
33 }
34