Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1724209

[PATCH] vt: Use bsearch library function in is_double_width

From Thomas Meyer <thomas@m3y3r.de>
Newsgroups linux.kernel
Subject [PATCH] vt: Use bsearch library function in is_double_width
Date 2017-08-31 15:10 +0200
Message-ID <ukxon-62o-35@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---
 drivers/tty/vt/vt.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 2ebaba16f785..725777a5d35e 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -102,6 +102,7 @@
 #include <linux/uaccess.h>
 #include <linux/kdb.h>
 #include <linux/ctype.h>
+#include <linux/bsearch.h>
 
 #define MAX_NR_CON_DRIVER 16
 
@@ -2142,22 +2143,15 @@ struct interval {
 	uint32_t last;
 };
 
-static int bisearch(uint32_t ucs, const struct interval *table, int max)
+static int ucs_cmp(const void *key, const void *elt)
 {
-	int min = 0;
-	int mid;
+	uint32_t ucs = *(uint32_t *)key;
+	struct interval e = *(struct interval *) elt;
 
-	if (ucs < table[0].first || ucs > table[max].last)
-		return 0;
-	while (max >= min) {
-		mid = (min + max) / 2;
-		if (ucs > table[mid].last)
-			min = mid + 1;
-		else if (ucs < table[mid].first)
-			max = mid - 1;
-		else
-			return 1;
-	}
+	if (ucs > e.last)
+		return 1;
+	else if (ucs < e.first)
+		return -1;
 	return 0;
 }
 
@@ -2169,7 +2163,8 @@ static int is_double_width(uint32_t ucs)
 		{ 0xFE10, 0xFE19 }, { 0xFE30, 0xFE6F }, { 0xFF00, 0xFF60 },
 		{ 0xFFE0, 0xFFE6 }, { 0x20000, 0x2FFFD }, { 0x30000, 0x3FFFD }
 	};
-	return bisearch(ucs, double_width, ARRAY_SIZE(double_width) - 1);
+	return bsearch(&ucs, double_width, ARRAY_SIZE(double_width),
+			sizeof(struct interval), ucs_cmp) != NULL;
 }
 
 static void con_flush(struct vc_data *vc, unsigned long draw_from,
-- 
2.11.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] vt: Use bsearch library function in is_double_width Thomas Meyer <thomas@m3y3r.de> - 2017-08-31 15:10 +0200
  Re: [PATCH] vt: Use bsearch library function in is_double_width Greg KH <gregkh@linuxfoundation.org> - 2017-08-31 15:40 +0200
  [PATCH v2] ipv6: sr: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-08-31 16:30 +0200
    Re: [PATCH v2] ipv6: sr: Use ARRAY_SIZE macro Greg KH <gregkh@linuxfoundation.org> - 2017-08-31 17:10 +0200
      Re: [PATCH v2] ipv6: sr: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-01 01:20 +0200
  [PATCH v2] vt: Use bsearch library function in is_double_width Thomas Meyer <thomas@m3y3r.de> - 2017-08-31 16:30 +0200
    Re: [PATCH v2] vt: Use bsearch library function in is_double_width Greg KH <gregkh@linuxfoundation.org> - 2017-08-31 17:10 +0200
      Re: [PATCH v2] vt: Use bsearch library function in is_double_width Thomas Meyer <thomas@m3y3r.de> - 2017-09-01 01:30 +0200

csiph-web