2016-04-01 08:31:23

by Sunil Shahu

[permalink] [raw]
Subject: [PATCH] Prevent unnecessary iteration in __handle_cmd

Break the loop after matching sectcmd is found. Remove redundant
variable copying.

Signed-off-by: Sunil Shahu <[email protected]>
---
iw.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/iw.c b/iw.c
index 0f511d9..73ae347 100644
--- a/iw.c
+++ b/iw.c
@@ -376,11 +376,9 @@ static int __handle_cmd(struct nl80211_state *state, enum id_input idby,
if (match && sectcmd->idby != command_idby)
continue;
if (strcmp(sectcmd->name, section) == 0)
- match = sectcmd;
+ break;
}

- sectcmd = match;
- match = NULL;
if (!sectcmd)
return 1;

--
1.9.1



2016-04-01 11:48:31

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH] Prevent unnecessary iteration in __handle_cmd

On Fri, 2016-04-01 at 14:01 +0530, Sunil Shahu wrote:
> Break the loop after matching sectcmd is found. Remove redundant
> variable copying.
>
> Signed-off-by: Sunil Shahu <[email protected]>
> ---
>  iw.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/iw.c b/iw.c
> index 0f511d9..73ae347 100644
> --- a/iw.c
> +++ b/iw.c
> @@ -376,11 +376,9 @@ static int __handle_cmd(struct nl80211_state
> *state, enum id_input idby,
>   if (match && sectcmd->idby != command_idby)
>   continue;
>   if (strcmp(sectcmd->name, section) == 0)
> - match = sectcmd;
> + break;
>   }
>  
> - sectcmd = match;
> - match = NULL;
>
I don't think this works - what if you reach the end of the loop?

johannes