* [PATCH BlueZ 1/1] src/agent.c : parse_io_capability Function optimization
@ 2020-07-24 12:25 luokai
2020-07-27 23:21 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 2+ messages in thread
From: luokai @ 2020-07-24 12:25 UTC (permalink / raw)
To: linux-bluetooth; +Cc: luokai
From: luokai <luokai@uniontech.com>
---
src/agent.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/src/agent.c b/src/agent.c
index e0ffcd22f..82baf608f 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -957,20 +957,24 @@ static void agent_destroy(gpointer data)
agent_unref(agent);
}
+static struct capability g_cap[] = {
+ {"", IO_CAPABILITY_KEYBOARDDISPLAY},
+ {"DisplayOnly", IO_CAPABILITY_DISPLAYONLY},
+ {"DisplayYesNo", IO_CAPABILITY_DISPLAYYESNO},
+ {"KeyboardOnly", IO_CAPABILITY_KEYBOARDONLY},
+ {"NoInputNoOutput", IO_CAPABILITY_NOINPUTNOOUTPUT},
+ {"KeyboardDisplay", IO_CAPABILITY_KEYBOARDDISPLAY}
+};
+
static uint8_t parse_io_capability(const char *capability)
{
- if (g_str_equal(capability, ""))
- return IO_CAPABILITY_KEYBOARDDISPLAY;
- if (g_str_equal(capability, "DisplayOnly"))
- return IO_CAPABILITY_DISPLAYONLY;
- if (g_str_equal(capability, "DisplayYesNo"))
- return IO_CAPABILITY_DISPLAYYESNO;
- if (g_str_equal(capability, "KeyboardOnly"))
- return IO_CAPABILITY_KEYBOARDONLY;
- if (g_str_equal(capability, "NoInputNoOutput"))
- return IO_CAPABILITY_NOINPUTNOOUTPUT;
- if (g_str_equal(capability, "KeyboardDisplay"))
- return IO_CAPABILITY_KEYBOARDDISPLAY;
+ size_t count = sizeof(g_cap) / sizeof(g_cap[0]);
+ for (size_t i = 0; i < count; i++)
+ {
+ if(g_str_equal(capability, g_cap[i].cap)) {
+ return g_cap[i].parse_capability;
+ }
+ }
return IO_CAPABILITY_INVALID;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH BlueZ 1/1] src/agent.c : parse_io_capability Function optimization
2020-07-24 12:25 [PATCH BlueZ 1/1] src/agent.c : parse_io_capability Function optimization luokai
@ 2020-07-27 23:21 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2020-07-27 23:21 UTC (permalink / raw)
To: luokai; +Cc: linux-bluetooth, luokai
Hi,
On Fri, Jul 24, 2020 at 5:27 AM luokai <454728735@qq.com> wrote:
>
> From: luokai <luokai@uniontech.com>
>
> ---
> src/agent.c | 28 ++++++++++++++++------------
> 1 file changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/src/agent.c b/src/agent.c
> index e0ffcd22f..82baf608f 100644
> --- a/src/agent.c
> +++ b/src/agent.c
> @@ -957,20 +957,24 @@ static void agent_destroy(gpointer data)
> agent_unref(agent);
> }
>
> +static struct capability g_cap[] = {
> + {"", IO_CAPABILITY_KEYBOARDDISPLAY},
> + {"DisplayOnly", IO_CAPABILITY_DISPLAYONLY},
> + {"DisplayYesNo", IO_CAPABILITY_DISPLAYYESNO},
> + {"KeyboardOnly", IO_CAPABILITY_KEYBOARDONLY},
> + {"NoInputNoOutput", IO_CAPABILITY_NOINPUTNOOUTPUT},
> + {"KeyboardDisplay", IO_CAPABILITY_KEYBOARDDISPLAY}
We usually spaces after { and before }.
> +};
> +
> static uint8_t parse_io_capability(const char *capability)
> {
> - if (g_str_equal(capability, ""))
> - return IO_CAPABILITY_KEYBOARDDISPLAY;
> - if (g_str_equal(capability, "DisplayOnly"))
> - return IO_CAPABILITY_DISPLAYONLY;
> - if (g_str_equal(capability, "DisplayYesNo"))
> - return IO_CAPABILITY_DISPLAYYESNO;
> - if (g_str_equal(capability, "KeyboardOnly"))
> - return IO_CAPABILITY_KEYBOARDONLY;
> - if (g_str_equal(capability, "NoInputNoOutput"))
> - return IO_CAPABILITY_NOINPUTNOOUTPUT;
> - if (g_str_equal(capability, "KeyboardDisplay"))
> - return IO_CAPABILITY_KEYBOARDDISPLAY;
> + size_t count = sizeof(g_cap) / sizeof(g_cap[0]);
If I recall correctly we do have macros for ARRAY_SIZE, check
src/shared/util.h, btw there also seems to be a problem with the
formatting on the above line:
Applying: src/agent.c : parse_io_capability Function optimization
.git/rebase-apply/patch:36: trailing whitespace.
size_t count = sizeof(g_cap) / sizeof(g_cap[0]);
error: 1 line adds whitespace errors.
> + for (size_t i = 0; i < count; i++)
> + {
> + if(g_str_equal(capability, g_cap[i].cap)) {
> + return g_cap[i].parse_capability;
> + }
> + }
> return IO_CAPABILITY_INVALID;
> }
>
> --
> 2.20.1
>
>
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-27 23:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 12:25 [PATCH BlueZ 1/1] src/agent.c : parse_io_capability Function optimization luokai
2020-07-27 23:21 ` Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).