lib: json: Efficiently pack field name, offset, alignment, type

This trades a little bit over 40 bytes (on x86) of text for a lot of
savings in rodata.  This is accomplished by using bitfields to pack the
field name length, offset, alignment, and the type tag into a single
32-bit unsigned integer instead of scattering this information into
four different integers.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
This commit is contained in:
Leandro Pereira 2018-04-18 18:14:22 -07:00 committed by Anas Nashif
commit 0ec79d6853
2 changed files with 38 additions and 22 deletions

View file

@ -476,8 +476,6 @@ static int decode_value(struct json_obj *obj,
static ptrdiff_t get_elem_size(const struct json_obj_descr *descr)
{
assert(descr->alignment);
switch (descr->type) {
case JSON_TOK_NUMBER:
return sizeof(s32_t);
@ -495,7 +493,7 @@ static ptrdiff_t get_elem_size(const struct json_obj_descr *descr)
for (i = 0; i < descr->object.sub_descr_len; i++) {
ptrdiff_t s = get_elem_size(&descr->object.sub_descr[i]);
total += ROUND_UP(s, descr->alignment);
total += ROUND_UP(s, descr->alignment + 1);
}
return total;