lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20230105200603.51113-1-sanpeqf@gmail.com>
Date:   Fri,  6 Jan 2023 04:06:03 +0800
From:   John Sanpe <sanpeqf@...il.com>
To:     linux-kernel@...r.kernel.org
Cc:     John Sanpe <sanpeqf@...il.com>
Subject: [PATCH] lib/ts_kmp: Remove duplicate logic to improve performance

Replace the kmp_init processing sequence, first perform case
conversion and then perform compute_prefix_tbl, this can
reduce a meaningless conversions.

Signed-off-by: John Sanpe <sanpeqf@...il.com>
---
 lib/ts_kmp.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/lib/ts_kmp.c b/lib/ts_kmp.c
index c77a3d537f24..9f83f9ee352c 100644
--- a/lib/ts_kmp.c
+++ b/lib/ts_kmp.c
@@ -72,17 +72,14 @@ static unsigned int kmp_find(struct ts_config *conf, struct ts_state *state)
 }
 
 static inline void compute_prefix_tbl(const u8 *pattern, unsigned int len,
-				      unsigned int *prefix_tbl, int flags)
+				      unsigned int *prefix_tbl)
 {
 	unsigned int k, q;
-	const u8 icase = flags & TS_IGNORECASE;
 
 	for (k = 0, q = 1; q < len; q++) {
-		while (k > 0 && (icase ? toupper(pattern[k]) : pattern[k])
-		    != (icase ? toupper(pattern[q]) : pattern[q]))
+		while (k > 0 && pattern[k] != pattern[q])
 			k = prefix_tbl[k-1];
-		if ((icase ? toupper(pattern[k]) : pattern[k])
-		    == (icase ? toupper(pattern[q]) : pattern[q]))
+		if (pattern[k] == pattern[q])
 			k++;
 		prefix_tbl[q] = k;
 	}
@@ -104,13 +101,13 @@ static struct ts_config *kmp_init(const void *pattern, unsigned int len,
 	conf->flags = flags;
 	kmp = ts_config_priv(conf);
 	kmp->pattern_len = len;
-	compute_prefix_tbl(pattern, len, kmp->prefix_tbl, flags);
 	kmp->pattern = (u8 *) kmp->prefix_tbl + prefix_tbl_len;
 	if (flags & TS_IGNORECASE)
 		for (i = 0; i < len; i++)
 			kmp->pattern[i] = toupper(((u8 *)pattern)[i]);
 	else
 		memcpy(kmp->pattern, pattern, len);
+	compute_prefix_tbl(kmp->pattern, len, kmp->prefix_tbl);
 
 	return conf;
 }
-- 
2.38.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ