summaryrefslogtreecommitdiff
path: root/trafgen_proto.c
diff options
context:
space:
mode:
Diffstat (limited to 'trafgen_proto.c')
-rw-r--r--trafgen_proto.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/trafgen_proto.c b/trafgen_proto.c
index e08c9c2..212e968 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -107,13 +107,12 @@ void proto_header_fields_add(struct proto_hdr *hdr,
static struct proto_field *proto_field_by_id(struct proto_hdr *hdr, uint32_t fid)
{
- int i;
-
- for (i = 0; i < hdr->fields_count; i++)
- if (hdr->fields[i].id == fid)
- return &hdr->fields[i];
+ /* Assume the fields are stored in the same order as the respective
+ * enum, so the index can be used for faster lookup here.
+ */
+ bug_on(hdr->fields[fid].id != fid);
- panic("Failed lookup field id %u for proto id %u\n", fid, hdr->id);
+ return &hdr->fields[fid];
}
bool proto_field_is_set(struct proto_hdr *hdr, uint32_t fid)