[PATCH 1/3] Add an inlined fast path for __libdw_form_val_len

Petr Machata pmachata at redhat.com
Thu Dec 12 10:47:20 UTC 2013


Josh Stone <jistone at redhat.com> writes:

> +  /* Small lookup table of forms with fixed lengths.  */
> +  static const uint8_t form_lengths[] =
> +    {
> +      [DW_FORM_data1] = 1, [DW_FORM_ref1] = 1, [DW_FORM_flag] = 1,
> +      [DW_FORM_data2] = 2, [DW_FORM_ref2] = 2,
> +      [DW_FORM_data4] = 4, [DW_FORM_ref4] = 4,
> +      [DW_FORM_data8] = 8, [DW_FORM_ref8] = 8, [DW_FORM_ref_sig8] = 8,
> +    };
> +
> +  /* Note that form_lengths[flag_present] is 0, like every other absent index.
> +   * But since flag_present's length truly is 0, check for it explicitly.  */
> +  if (form == DW_FORM_flag_present)
> +    return 0;

One way to get rid of this if would be to store X | 0x80 in the table
(including 0 | 0x80 for DW_FORM_flag_present), and then return
len ^ 0x80 later.  I don't feel strongly about this though, and
certainly not if it offsets the performance gains again ;)

> +
> +  /* Return immediately for forms with fixed lengths.  */
> +  if (form < sizeof(form_lengths) / sizeof(form_lengths[0]))

Space after sizeof

> +    {
> +      size_t len = form_lengths[form];
> +      if (len != 0)
> +	return len;

Fine otherwise.

Thanks,
PM


More information about the elfutils-devel mailing list