Refactor out functions to get hasbit offset and mask.

PiperOrigin-RevId: 486738238
pull/13171/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 75907f7af9
commit d4425d3f5b
  1. 2
      upb/collections/array_internal.h
  2. 15
      upb/msg_internal.h
  3. 2
      upb/string_view.h

@ -39,12 +39,14 @@
extern "C" {
#endif
// LINT.IfChange(struct_definition)
// Our internal representation for repeated fields.
struct upb_Array {
uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */
size_t size; /* The number of elements in the array. */
size_t capacity; /* Allocated storage. Measured in elements. */
};
// LINT.ThenChange(GoogleInternalName1)
UPB_INLINE const void* _upb_array_constptr(const upb_Array* arr) {
UPB_ASSERT((arr->data & 7) <= 4);

@ -340,18 +340,25 @@ const upb_Message_Extension* _upb_Message_Getext(
void _upb_Message_Clearext(upb_Message* msg, const upb_MiniTableExtension* ext);
// LINT.IfChange(presence_logic)
/** Hasbit access *************************************************************/
UPB_INLINE size_t _upb_hasbit_ofs(size_t idx) { return idx / 8; }
UPB_INLINE char _upb_hasbit_mask(size_t idx) { return 1 << (idx % 8); }
UPB_INLINE bool _upb_hasbit(const upb_Message* msg, size_t idx) {
return (*UPB_PTR_AT(msg, idx / 8, const char) & (1 << (idx % 8))) != 0;
return (*UPB_PTR_AT(msg, _upb_hasbit_ofs(idx), const char) &
_upb_hasbit_mask(idx)) != 0;
}
UPB_INLINE void _upb_sethas(const upb_Message* msg, size_t idx) {
(*UPB_PTR_AT(msg, idx / 8, char)) |= (char)(1 << (idx % 8));
(*UPB_PTR_AT(msg, _upb_hasbit_ofs(idx), char)) |= _upb_hasbit_mask(idx);
}
UPB_INLINE void _upb_clearhas(const upb_Message* msg, size_t idx) {
(*UPB_PTR_AT(msg, idx / 8, char)) &= (char)(~(1 << (idx % 8)));
(*UPB_PTR_AT(msg, _upb_hasbit_ofs(idx), char)) &= ~_upb_hasbit_mask(idx);
}
UPB_INLINE size_t _upb_Message_Hasidx(const upb_MiniTableField* f) {
@ -403,6 +410,8 @@ UPB_INLINE bool _upb_has_submsg_nohasbit(const upb_Message* msg, size_t ofs) {
return *UPB_PTR_AT(msg, ofs, const upb_Message*) != NULL;
}
// LINT.ThenChange(GoogleInternalName2)
/* Map entries aren't actually stored, they are only used during parsing. For
* parsing, it helps a lot if all map entry messages have the same layout.
* The compiler and def.c must ensure that all map entries have this layout. */

@ -37,10 +37,12 @@
extern "C" {
#endif
// LINT.IfChange(struct_definition)
typedef struct {
const char* data;
size_t size;
} upb_StringView;
// LINT.ThenChange(GoogleInternalName0)
UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data,
size_t size) {

Loading…
Cancel
Save