File indexing completed on 2025-01-30 10:25:23
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_
0009 #define UPB_MINI_TABLE_INTERNAL_ENUM_H_
0010
0011 #include <stdint.h>
0012
0013
0014 #include "upb/port/def.inc"
0015
0016 struct upb_MiniTableEnum {
0017 uint32_t UPB_PRIVATE(mask_limit);
0018 uint32_t UPB_PRIVATE(value_count);
0019 uint32_t UPB_PRIVATE(data)[];
0020 };
0021
0022 #ifdef __cplusplus
0023 extern "C" {
0024 #endif
0025
0026 UPB_API_INLINE bool upb_MiniTableEnum_CheckValue(
0027 const struct upb_MiniTableEnum* e, uint32_t val) {
0028 if (UPB_LIKELY(val < 64)) {
0029 const uint64_t mask =
0030 e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32);
0031 const uint64_t bit = 1ULL << val;
0032 return (mask & bit) != 0;
0033 }
0034 if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) {
0035 const uint32_t mask = e->UPB_PRIVATE(data)[val / 32];
0036 const uint32_t bit = 1ULL << (val % 32);
0037 return (mask & bit) != 0;
0038 }
0039
0040
0041 const uint32_t* start =
0042 &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32];
0043 const uint32_t* limit = &e->UPB_PRIVATE(
0044 data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)];
0045 for (const uint32_t* p = start; p < limit; p++) {
0046 if (*p == val) return true;
0047 }
0048 return false;
0049 }
0050
0051 #ifdef __cplusplus
0052 }
0053 #endif
0054
0055 #include "upb/port/undef.inc"
0056
0057 #endif