Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
From: luokai <454728735@qq.com>
To: linux-bluetooth@vger.kernel.org
Cc: luokai <luokai@uniontech.com>
Subject: [PATCH BlueZ 1/1] src/agent.c : parse_io_capability Function optimization
Date: Fri, 24 Jul 2020 20:25:07 +0800
Message-ID: <20200724122507.27671-1-454728735@qq.com> (raw)

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




             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-24 12:25 luokai [this message]
2020-07-27 23:21 ` Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200724122507.27671-1-454728735@qq.com \
    --to=454728735@qq.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luokai@uniontech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org
	public-inbox-index linux-bluetooth

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git