summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/upb_def.c2
-rw-r--r--core/upb_def.h4
-rw-r--r--core/upb_msg.c2
-rw-r--r--core/upb_msg.h2
4 files changed, 7 insertions, 3 deletions
diff --git a/core/upb_def.c b/core/upb_def.c
index 8abb8bc..651afc1 100644
--- a/core/upb_def.c
+++ b/core/upb_def.c
@@ -727,6 +727,8 @@ static upb_flow_t upb_msgdef_endmsg(void *_b) {
// want to use a different ordering that puts all the required bits
// together.
f->field_index = i;
+ f->set_bit_mask = 1 << (i % 8);
+ f->set_bit_offset = i / 8;
size_t size, align;
if (upb_isarray(f)) {
diff --git a/core/upb_def.h b/core/upb_def.h
index 34f31ec..28cc258 100644
--- a/core/upb_def.h
+++ b/core/upb_def.h
@@ -101,14 +101,16 @@ typedef struct _upb_fielddef {
uint32_t byte_offset; // Where in a upb_msg to find the data.
// These are set only when this fielddef is part of a msgdef.
+ upb_field_number_t number;
upb_field_count_t field_index; // Indicates set bit.
- upb_field_number_t number;
upb_fieldtype_t type;
upb_label_t label;
// True if we own a ref on "def" (above). This is true unless this edge is
// part of a cycle.
bool owned;
+ uint8_t set_bit_mask;
+ uint16_t set_bit_offset;
} upb_fielddef;
// A variety of tests about the type of a field.
diff --git a/core/upb_msg.c b/core/upb_msg.c
index 05ee1e9..9dfbea4 100644
--- a/core/upb_msg.c
+++ b/core/upb_msg.c
@@ -142,7 +142,7 @@ void upb_msg_recycle(upb_msg **_msg, upb_msgdef *msgdef) {
}
INLINE void upb_msg_sethas(upb_msg *msg, upb_fielddef *f) {
- msg->data[f->field_index/8] |= (1 << (f->field_index % 8));
+ msg->data[f->set_bit_offset] |= f->set_bit_mask;
}
static upb_valueptr upb_msg_getappendptr(upb_msg *msg, upb_fielddef *f) {
diff --git a/core/upb_msg.h b/core/upb_msg.h
index 1318e08..8a3c63f 100644
--- a/core/upb_msg.h
+++ b/core/upb_msg.h
@@ -198,7 +198,7 @@ void upb_msg_recycle(upb_msg **msg, upb_msgdef *msgdef);
// Tests whether the given field is explicitly set, or whether it will return a
// default.
INLINE bool upb_msg_has(upb_msg *msg, upb_fielddef *f) {
- return (msg->data[f->field_index/8] & (1 << (f->field_index % 8))) != 0;
+ return (msg->data[f->set_bit_offset] & f->set_bit_mask) != 0;
}
INLINE upb_value upb_msg_get(upb_msg *msg, upb_fielddef *f) {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback