ASoC: Intel: mrfld: simplify sst_fill_widget_module_info
Subsystems (3)
PATCH 1/1 ASoC: Intel: mrfld: simplify sst_fill_widget_module_info
Some tiny improvements, cutting 180 bytes off the generated code.
- use strchr() for single-character needle
- compute index using pointer subtraction instead of two strlen() calls
- factor out the common check for whether the initial part of kctl->id.name (before the space) is identical to w->name.
--- sound/soc/intel/atom/sst-atom-controls.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
sound/soc/intel/atom/sst-atom-controls.c +8 -12
@@ -1280,36 +1280,32 @@ static int sst_fill_widget_module_info(struct snd_soc_dapm_widget *w,down_read (&card->controls_rwsem);list_for_each_entry (kctl, &card->controls, list) { - idx =strstr (kctl->id.name," " ); + idx =strchr (kctl->id.name,' ' );if (idx ==NULL )continue ; - index =strlen (kctl->id.name) -strlen (idx); + index = idx - (char *)kctl->id.name; +if (strncmp (kctl->id.name, w->name, index)) +continue ; -if (strstr (kctl->id.name,"Volume" ) && - !strncmp (kctl->id.name, w->name, index)) +if (strstr (kctl->id.name,"Volume" )) ret =sst_fill_module_list (kctl, w,SST_MODULE_GAIN ); -else if (strstr (kctl->id.name,"params" ) && - !strncmp (kctl->id.name, w->name, index)) +else if (strstr (kctl->id.name,"params" )) ret =sst_fill_module_list (kctl, w,SST_MODULE_ALGO );else if (strstr (kctl->id.name,"Switch" ) && - !strncmp (kctl->id.name, w->name, index) &&strstr (kctl->id.name,"Gain" )) {struct sst_gain_mixer_control *mc = (void *)kctl->private_value; mc->w = w; - }else if (strstr (kctl->id.name,"interleaver" ) && - !strncmp (kctl->id.name, w->name, index)) { + }else if (strstr (kctl->id.name,"interleaver" )) {struct sst_enum *e = (void *)kctl->private_value; e->w = w; - }else if (strstr (kctl->id.name,"deinterleaver" ) && - !strncmp (kctl->id.name, w->name, index)) { - + }else if (strstr (kctl->id.name,"deinterleaver" )) {struct sst_enum *e = (void *)kctl->private_value; e->w = w;
Signature · 1 line
2.1.3
Quoted 9 lines · Rasmus Villemoes
Some tiny improvements, cutting 180 bytes off the generated code.
- use
strchr()for single-character needle- compute index using pointer subtraction instead of two
strlen()calls- factor out the common check for whether the initial part of
kctl->id.name(before the space) is identical tow->name.
Also Terry did the tests on this patch so would be good to add
Signature · 1 line
~Vinod
Quoted 58 lines
Signed-off-by Rasmus Villemoes <[email protected]>--- sound/soc/intel/atom/sst-atom-controls.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)sound/soc/intel/atom/sst-atom-controls.c +8
-12@@ -1280,36 +1280,32 @@ static int sst_fill_widget_module_info(struct snd_soc_dapm_widget *w,down_read (&card->controls_rwsem);list_for_each_entry (kctl, &card->controls, list) { - idx =strstr (kctl->id.name," " ); + idx =strchr (kctl->id.name,' ' );if (idx ==NULL )continue ; - index =strlen (kctl->id.name) -strlen (idx); + index = idx - (char *)kctl->id.name; +if (strncmp (kctl->id.name, w->name, index)) +continue ; -if (strstr (kctl->id.name,"Volume" ) && - !strncmp (kctl->id.name, w->name, index)) +if (strstr (kctl->id.name,"Volume" )) ret =sst_fill_module_list (kctl, w,SST_MODULE_GAIN ); -else if (strstr (kctl->id.name,"params" ) && - !strncmp (kctl->id.name, w->name, index)) +else if (strstr (kctl->id.name,"params" )) ret =sst_fill_module_list (kctl, w,SST_MODULE_ALGO );else if (strstr (kctl->id.name,"Switch" ) && - !strncmp (kctl->id.name, w->name, index) &&strstr (kctl->id.name,"Gain" )) {struct sst_gain_mixer_control *mc = (void *)kctl->private_value; mc->w = w; - }else if (strstr (kctl->id.name,"interleaver" ) && - !strncmp (kctl->id.name, w->name, index)) { + }else if (strstr (kctl->id.name,"interleaver" )) {struct sst_enum *e = (void *)kctl->private_value; e->w = w; - }else if (strstr (kctl->id.name,"deinterleaver" ) && - !strncmp (kctl->id.name, w->name, index)) { - + }else if (strstr (kctl->id.name,"deinterleaver" )) {struct sst_enum *e = (void *)kctl->private_value; e->w = w;Signature · 1 line
2.1.3
Quoted 1 line · Rasmus Villemoes
Some tiny improvements, cutting 180 bytes off the generated code.
Applied, thanks