upb: reuse upb_Message_Internal buffer after a upb_Message_Clear()

PiperOrigin-RevId: 622913413
pull/16436/head
Eric Salo 8 months ago committed by Copybara-Service
parent 54f512bd67
commit 52aa23f3fc
  1. 7
      upb/message/internal/accessors.h

@ -296,7 +296,14 @@ UPB_INLINE bool _upb_Message_SetExtensionField(
UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg, UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg,
const upb_MiniTable* m) { const upb_MiniTable* m) {
UPB_ASSERT(!upb_Message_IsFrozen(msg)); UPB_ASSERT(!upb_Message_IsFrozen(msg));
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
memset(msg, 0, m->UPB_PRIVATE(size)); memset(msg, 0, m->UPB_PRIVATE(size));
if (in) {
// Reset the internal buffer to empty.
in->unknown_end = sizeof(upb_Message_Internal);
in->ext_begin = in->size;
UPB_PRIVATE(_upb_Message_SetInternal)(msg, in);
}
} }
UPB_API_INLINE void upb_Message_ClearBaseField(struct upb_Message* msg, UPB_API_INLINE void upb_Message_ClearBaseField(struct upb_Message* msg,

Loading…
Cancel
Save