ALSA: control: Use xarray for faster lookups
The control elements are managed in a single linked list and we
traverse the whole list for matching each numid or ctl id per every
inquiry of a control element. This is OK-ish for a small number of
elements but obviously it doesn't scale. Especially the matching with
the ctl id takes time because it checks each field of the snd_ctl_id
element, e.g. the name string is matched with strcmp().
This patch adds the hash tables with Xarray in addition to the linked
list for improving the lookup speed of a control element. There are
two xarray tables added to the card; one for numid and another for ctl
id. For the numid, we use the numid as the index, while for the ctl
id, we calculate a hash key.
The lookup is done via a single xa_load(). When nothing hits, we look
through the full list entries as a fallback. So, the inquiry for a
non-existing element would take (even slightly longer) time with this
patch.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
4 files changed