|
|
@ -638,29 +638,26 @@ static void upb_MtDecoder_ParseMessage(upb_MtDecoder* d, const char* data, |
|
|
|
upb_MtDecoder_AllocateSubs(d, sub_count); |
|
|
|
upb_MtDecoder_AllocateSubs(d, sub_count); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define UPB_COMPARE_INTEGERS(a, b) ((a) < (b) ? -1 : ((a) == (b) ? 0 : 1)) |
|
|
|
|
|
|
|
#define UPB_COMBINE(rep, ty, idx) (((rep << type_bits) | ty) << idx_bits) | idx |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int upb_MtDecoder_CompareFields(const void* _a, const void* _b) { |
|
|
|
int upb_MtDecoder_CompareFields(const void* _a, const void* _b) { |
|
|
|
const upb_LayoutItem* a = _a; |
|
|
|
const upb_LayoutItem* a = _a; |
|
|
|
const upb_LayoutItem* b = _b; |
|
|
|
const upb_LayoutItem* b = _b; |
|
|
|
// Currently we just sort by:
|
|
|
|
// Currently we just sort by:
|
|
|
|
// 1. rep (smallest fields first)
|
|
|
|
// 1. rep (smallest fields first)
|
|
|
|
// 2. type (oneof cases first)
|
|
|
|
// 2. type (oneof cases first)
|
|
|
|
// 2. field_number (smallest numbers first)
|
|
|
|
// 2. field_index (smallest numbers first)
|
|
|
|
// The main goal of this is to reduce space lost to padding.
|
|
|
|
// The main goal of this is to reduce space lost to padding.
|
|
|
|
// Later we may have more subtle reasons to prefer a different ordering.
|
|
|
|
// Later we may have more subtle reasons to prefer a different ordering.
|
|
|
|
const int rep_bits = _upb_Log2Ceiling(kUpb_FieldRep_Max); |
|
|
|
const int rep_bits = _upb_Log2Ceiling(kUpb_FieldRep_Max); |
|
|
|
const int type_bits = _upb_Log2Ceiling(kUpb_LayoutItemType_Max); |
|
|
|
const int type_bits = _upb_Log2Ceiling(kUpb_LayoutItemType_Max); |
|
|
|
const int idx_bits = (sizeof(a->field_index) * 8); |
|
|
|
const int idx_bits = (sizeof(a->field_index) * 8); |
|
|
|
UPB_ASSERT(idx_bits + rep_bits + type_bits < 32); |
|
|
|
UPB_ASSERT(idx_bits + rep_bits + type_bits < 32); |
|
|
|
|
|
|
|
#define UPB_COMBINE(rep, ty, idx) (((rep << type_bits) | ty) << idx_bits) | idx |
|
|
|
uint32_t a_packed = UPB_COMBINE(a->rep, a->type, a->field_index); |
|
|
|
uint32_t a_packed = UPB_COMBINE(a->rep, a->type, a->field_index); |
|
|
|
uint32_t b_packed = UPB_COMBINE(b->rep, b->type, b->field_index); |
|
|
|
uint32_t b_packed = UPB_COMBINE(b->rep, b->type, b->field_index); |
|
|
|
return UPB_COMPARE_INTEGERS(a_packed, b_packed); |
|
|
|
assert(a_packed != b_packed); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef UPB_COMBINE |
|
|
|
#undef UPB_COMBINE |
|
|
|
#undef UPB_COMPARE_INTEGERS |
|
|
|
return a < b ? -1 : 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { |
|
|
|
static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { |
|
|
|
// Add items for all non-oneof fields (oneofs were already added).
|
|
|
|
// Add items for all non-oneof fields (oneofs were already added).
|
|
|
|