Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1030859ybb; Wed, 25 Mar 2020 14:18:51 -0700 (PDT) X-Google-Smtp-Source: ADFU+vviMKG3RoJLYT+ZrVm/67Boz3aIfMOWpWdPzjuvIR1PAC096319s9L4+aeykaLGWdU+AuQT X-Received: by 2002:aca:cf8a:: with SMTP id f132mr3762634oig.151.1585171131212; Wed, 25 Mar 2020 14:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585171131; cv=none; d=google.com; s=arc-20160816; b=sMe6eOGN96KqMWG4gHiyjl16DvZeWVYw8KuEYpVQ2aipdPmghPkFON8o2QkaHdrdQd fK3ZUB2tLuvAzX2zJctxinmhUkl2rl/bplHPTgRSUwP5AMCnJ7bUNlwdsbITBH78M0oV IcFCrGKONCRluhKdizPWpaGlM4vxdUSbf+mfMYMC4v7CIn1MwXyyewKFKrpxAPVa2o3y pwgR92zyaxFVVrp5U1pGJGozTUQJ64x1RMsApEAcU3eLHSyufer2sv5LyXxmiNNpDpfa /Q6/LChdmngvNForjinhDzzA/1fZAFVNj+MT9kjUSbE/LB5G7aL02TFhC3WfDSyGOq80 XJig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=CrGVbc2jC++xgTMMK0Dha41d7GCD/1D+lz4Z+kwc8n4=; b=z4vLUulbGRw0dmsOxsb54VI8UJqWvhlx+8SL34d7zomGe2yLgkeB2ZbypAhRQA9uqq FupGkKVWjhloVej2kv/UmieevIXNAYrSAl1Z7M0fxRDieSg3+8j+MDnpkXQuVbvl6K8j yY0CDc17wMzzzwUt1gWzVcTar+QNmLi3c4E66NW+asavTkoLY2ymProt3Uhm02Yx4o3s lCrmiuQW3gwTcD/H4ujHV7vDx8/QRzow2/y0B+uZBlbaHubAFpp0mZHzpcIgusc2VFne nKpPBX3Og+qsgu/TQVO3ibqHxWWVHcJGR6q1LqXjyWwybFkd6vSSh9pXhiNC8nOdwdaS esDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2si128180otk.247.2020.03.25.14.18.39; Wed, 25 Mar 2020 14:18:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727356AbgCYVSf (ORCPT + 99 others); Wed, 25 Mar 2020 17:18:35 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:39570 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727351AbgCYVSf (ORCPT ); Wed, 25 Mar 2020 17:18:35 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id D03F528666B From: Gabriel Krisman Bertazi To: tytso@mit.edu Cc: linux-ext4@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH e2fsprogs 04/11] ext2fs: Implement faster CI comparison of strings Date: Wed, 25 Mar 2020 17:18:04 -0400 Message-Id: <20200325211812.2971787-5-krisman@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200325211812.2971787-1-krisman@collabora.com> References: <20200325211812.2971787-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Instead of calling casefold two times and memcmp the result, which require allocating a temporary buffer for the casefolded version, add a strcasecmp-like method to perform the comparison of each code-point during the casefold itself. This method is exposed because it needs to be used directly by fsck. Signed-off-by: Gabriel Krisman Bertazi --- lib/ext2fs/ext2fs.h | 4 ++++ lib/ext2fs/ext2fsP.h | 4 ++++ lib/ext2fs/nls_utf8.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index bf54130f4edb..c5815c37bbb6 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -1613,6 +1613,10 @@ extern errcode_t ext2fs_new_dir_inline_data(ext2_filsys fs, ext2_ino_t dir_ino, extern const struct ext2fs_nls_table *ext2fs_load_nls_table(int encoding); extern int ext2fs_check_encoded_name(const struct ext2fs_nls_table *table, char *s, size_t len, char **pos); +extern int ext2fs_casefold_cmp(const struct ext2fs_nls_table *table, + const unsigned char *str1, size_t len1, + const unsigned char *str2, size_t len2); + /* mkdir.c */ extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, diff --git a/lib/ext2fs/ext2fsP.h b/lib/ext2fs/ext2fsP.h index 30564ded1e2b..99239be007f2 100644 --- a/lib/ext2fs/ext2fsP.h +++ b/lib/ext2fs/ext2fsP.h @@ -106,6 +106,10 @@ struct ext2fs_nls_ops { unsigned char *dest, size_t dlen); int (*validate)(const struct ext2fs_nls_table *table, char *s, size_t len, char **pos); + int (*casefold_cmp)(const struct ext2fs_nls_table *table, + const unsigned char *str1, size_t len1, + const unsigned char *str2, size_t len2); + }; /* Function prototypes */ diff --git a/lib/ext2fs/nls_utf8.c b/lib/ext2fs/nls_utf8.c index f59484142e19..f85b8e77e47b 100644 --- a/lib/ext2fs/nls_utf8.c +++ b/lib/ext2fs/nls_utf8.c @@ -949,9 +949,36 @@ static int utf8_validate(const struct ext2fs_nls_table *table, return 0; } +static int utf8_casefold_cmp(const struct ext2fs_nls_table *table, + const unsigned char *str1, size_t len1, + const unsigned char *str2, size_t len2) +{ + const struct utf8data *data = utf8nfdicf(table->version); + int c1, c2; + struct utf8cursor cur1, cur2; + + if (utf8ncursor(&cur1, data, (const char *) str1, len1) < 0) + return -1; + if (utf8ncursor(&cur2, data, (const char *) str2, len2) < 0) + return -1; + + do { + c1 = utf8byte(&cur1); + c2 = utf8byte(&cur2); + + if (c1 < 0 || c2 < 0) + return -1; + if (c1 != c2) + return c1 - c2; + } while (c1); + + return 0; +} + static const struct ext2fs_nls_ops utf8_ops = { .casefold = utf8_casefold, .validate = utf8_validate, + .casefold_cmp = utf8_casefold_cmp, }; static const struct ext2fs_nls_table nls_utf8 = { @@ -972,3 +999,9 @@ int ext2fs_check_encoded_name(const struct ext2fs_nls_table *table, { return table->ops->validate(table, name, len, pos); } +int ext2fs_casefold_cmp(const struct ext2fs_nls_table *table, + const unsigned char *str1, size_t len1, + const unsigned char *str2, size_t len2) +{ + return table->ops->casefold_cmp(table, str1, len1, str2, len2); +} -- 2.25.0