2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

meta-flow: Compact struct field_array.

struct field_array is included in each ofgroup, but the current
implementation is very sparse, using more than 20kb of data.

Also loop over 1-bits instead of each and every MF type to make
processing faster.

Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Jarno Rajahalme
2016-07-29 16:52:04 -07:00
parent 75868d0e7d
commit e8dba71979
7 changed files with 99 additions and 44 deletions

View File

@@ -2515,7 +2515,28 @@ void
field_array_set(enum mf_field_id id, const union mf_value *value,
struct field_array *fa)
{
size_t i, offset = 0;
ovs_assert(id < MFF_N_IDS);
/* Find the spot for 'id'. */
BITMAP_FOR_EACH_1 (i, id, fa->used.bm) {
offset += mf_from_id(i)->n_bytes;
}
size_t value_size = mf_from_id(id)->n_bytes;
/* make room if necessary. */
if (!bitmap_is_set(fa->used.bm, id)) {
fa->values = xrealloc(fa->values, fa->values_size + value_size);
/* Move remainder forward, if any. */
if (offset < fa->values_size) {
memmove(fa->values + offset + value_size, fa->values + offset,
fa->values_size - offset);
}
fa->values_size += value_size;
}
bitmap_set1(fa->used.bm, id);
fa->value[id] = *value;
memcpy(fa->values + offset, value, value_size);
}