|
|
|
@ -918,6 +918,8 @@ UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); |
|
|
|
|
#ifndef UPB_MINI_TABLE_ENUM_H_ |
|
|
|
|
#define UPB_MINI_TABLE_ENUM_H_ |
|
|
|
|
|
|
|
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ |
|
|
|
|
#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ |
|
|
|
@ -932,30 +934,26 @@ struct upb_MiniTableEnum { |
|
|
|
|
uint32_t data[]; // Bitmask + enumerated values follow.
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
typedef enum { |
|
|
|
|
_kUpb_FastEnumCheck_ValueIsInEnum = 0, |
|
|
|
|
_kUpb_FastEnumCheck_ValueIsNotInEnum = 1, |
|
|
|
|
_kUpb_FastEnumCheck_CannotCheckFast = 2, |
|
|
|
|
} _kUpb_FastEnumCheck_Status; |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
extern "C" { |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
UPB_INLINE _kUpb_FastEnumCheck_Status _upb_MiniTable_CheckEnumValueFast( |
|
|
|
|
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( |
|
|
|
|
const struct upb_MiniTableEnum* e, uint32_t val) { |
|
|
|
|
if (UPB_UNLIKELY(val >= 64)) return _kUpb_FastEnumCheck_CannotCheckFast; |
|
|
|
|
uint64_t mask = e->data[0] | ((uint64_t)e->data[1] << 32); |
|
|
|
|
return (mask & (1ULL << val)) ? _kUpb_FastEnumCheck_ValueIsInEnum |
|
|
|
|
: _kUpb_FastEnumCheck_ValueIsNotInEnum; |
|
|
|
|
} |
|
|
|
|
if (UPB_LIKELY(val < 64)) { |
|
|
|
|
const uint64_t mask = e->data[0] | ((uint64_t)e->data[1] << 32); |
|
|
|
|
const uint64_t bit = 1ULL << val; |
|
|
|
|
return (mask & bit) != 0; |
|
|
|
|
} |
|
|
|
|
if (UPB_LIKELY(val < e->mask_limit)) { |
|
|
|
|
const uint32_t mask = e->data[val / 32]; |
|
|
|
|
const uint32_t bit = 1ULL << (val % 32); |
|
|
|
|
return (mask & bit) != 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE bool _upb_MiniTable_CheckEnumValueSlow( |
|
|
|
|
const struct upb_MiniTableEnum* e, uint32_t val) { |
|
|
|
|
if (val < e->mask_limit) return e->data[val / 32] & (1ULL << (val % 32)); |
|
|
|
|
// OPT: binary search long lists?
|
|
|
|
|
const uint32_t* start = &e->data[e->mask_limit / 32]; |
|
|
|
|
const uint32_t* limit = &e->data[(e->mask_limit / 32) + e->value_count]; |
|
|
|
|
const uint32_t* limit = &e->data[e->mask_limit / 32 + e->value_count]; |
|
|
|
|
for (const uint32_t* p = start; p < limit; p++) { |
|
|
|
|
if (*p == val) return true; |
|
|
|
|
} |
|
|
|
@ -978,13 +976,9 @@ extern "C" { |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Validates enum value against range defined by enum mini table.
|
|
|
|
|
UPB_INLINE bool upb_MiniTableEnum_CheckValue(const struct upb_MiniTableEnum* e, |
|
|
|
|
UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, |
|
|
|
|
uint32_t val) { |
|
|
|
|
_kUpb_FastEnumCheck_Status status = _upb_MiniTable_CheckEnumValueFast(e, val); |
|
|
|
|
if (UPB_UNLIKELY(status == _kUpb_FastEnumCheck_CannotCheckFast)) { |
|
|
|
|
return _upb_MiniTable_CheckEnumValueSlow(e, val); |
|
|
|
|
} |
|
|
|
|
return status == _kUpb_FastEnumCheck_ValueIsInEnum ? true : false; |
|
|
|
|
return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
@ -1120,8 +1114,6 @@ typedef enum { |
|
|
|
|
kUpb_ExtMode_IsMapEntry = 4, |
|
|
|
|
} upb_ExtMode; |
|
|
|
|
|
|
|
|
|
union upb_MiniTableSub; |
|
|
|
|
|
|
|
|
|
// upb_MiniTable represents the memory layout of a given upb_MessageDef.
|
|
|
|
|
// The members are public so generated code can initialize them,
|
|
|
|
|
// but users MUST NOT directly read or write any of its members.
|
|
|
|
@ -1170,15 +1162,18 @@ UPB_INLINE uint64_t upb_MiniTable_requiredmask(const struct upb_MiniTable* l) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ |
|
|
|
|
#define UPB_MINI_TABLE_INTERNAL_SUB_H_ |
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
union upb_MiniTableSub { |
|
|
|
|
const struct upb_MiniTable* submsg; |
|
|
|
|
const struct upb_MiniTableEnum* subenum; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ |
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
@ -3308,7 +3303,6 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, |
|
|
|
|
#ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ |
|
|
|
|
#define UPB_MINI_TABLE_INTERNAL_FILE_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
struct upb_MiniTableFile { |
|
|
|
|