[PATCH 8/8] v4l2-utils: turn prefixes to a constexpr array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allows usage of a single any_of instead of a raw loop.

Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
---
 utils/v4l2-ctl/v4l2-ctl-common.cpp | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp
index 17ad488dd..2b6dd6d13 100644
--- a/utils/v4l2-ctl/v4l2-ctl-common.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp
@@ -116,28 +116,14 @@ void common_usage()
 	       );
 }
 
-static const char *prefixes[] = {
-	"video",
-	"radio",
-	"vbi",
-	"swradio",
-	"v4l-subdev",
-	"v4l-touch",
-	"media",
-	nullptr
+static constexpr std::array<const char *, 7> prefixes{
+	"video", "radio", "vbi", "swradio", "v4l-subdev", "v4l-touch", "media",
 };
 
 static bool is_v4l_dev(const char *name)
 {
-	for (unsigned i = 0; prefixes[i]; i++) {
-		unsigned l = strlen(prefixes[i]);
-
-		if (!memcmp(name, prefixes[i], l)) {
-			if (isdigit(name[l]))
-				return true;
-		}
-	}
-	return false;
+	return std::any_of(prefixes.begin(), prefixes.end(),
+			   [=](const char *prefix) { return !strcmp(name, prefix) && isdigit(name[strlen(prefix)]); });
 }
 
 static int calc_node_val(const char *s)
@@ -146,7 +132,7 @@ static int calc_node_val(const char *s)
 
 	s = std::strrchr(s, '/') + 1;
 
-	for (unsigned i = 0; prefixes[i]; i++) {
+	for (size_t i = 0; i < prefixes.size(); i++) {
 		unsigned l = strlen(prefixes[i]);
 
 		if (!memcmp(s, prefixes[i], l)) {
-- 
2.30.2




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux