Skip to content

Commit

Permalink
module: unicode: remove unused tolower transformations
Browse files Browse the repository at this point in the history
With the previous patch this yields
  $ size -G ./module/zfs.ko ./module/zfs.new.ko
        text       data        bss      total filename
     2865126    1597982     755768    5218876 ./module/zfs.ko
     2864038    1429784     755768    5049590 ./module/zfs.new.ko
       -1088    -168198
         -1k      -164k

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#16704
  • Loading branch information
nabijaczleweli authored and behlendorf committed Nov 5, 2024
1 parent e17a969 commit 60c202c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
4 changes: 4 additions & 0 deletions include/sys/u8_textprep.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ extern "C" {
*/
#define U8_STRCMP_CS (0x00000001)
#define U8_STRCMP_CI_UPPER (0x00000002)
#if 0
#define U8_STRCMP_CI_LOWER (0x00000004)
#endif

#define U8_CANON_DECOMP (0x00000010)
#define U8_COMPAT_DECOMP (0x00000020)
Expand All @@ -57,7 +59,9 @@ extern "C" {
#define U8_STRCMP_NFKC (U8_COMPAT_DECOMP | U8_CANON_COMP)

#define U8_TEXTPREP_TOUPPER (U8_STRCMP_CI_UPPER)
#ifdef U8_STRCMP_CI_LOWER
#define U8_TEXTPREP_TOLOWER (U8_STRCMP_CI_LOWER)
#endif

#define U8_TEXTPREP_NFD (U8_STRCMP_NFD)
#define U8_TEXTPREP_NFC (U8_STRCMP_NFC)
Expand Down
2 changes: 2 additions & 0 deletions include/sys/u8_textprep_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -27638,6 +27638,7 @@ static const uchar_t u8_case_common_b2_tbl[U8_UNICODE_LATEST + 1][2][256] = {

};

#ifdef U8_STRCMP_CI_LOWER
static const u8_displacement_t u8_tolower_b3_tbl[
U8_UNICODE_LATEST + 1][5][256] =
{
Expand Down Expand Up @@ -31422,6 +31423,7 @@ static const uchar_t u8_tolower_final_tbl[U8_UNICODE_LATEST + 1][2299] = {
0x90, 0x91, 0x8F,
},
};
#endif

static const u8_displacement_t u8_toupper_b3_tbl[
U8_UNICODE_LATEST + 1][5][256] =
Expand Down
37 changes: 32 additions & 5 deletions module/unicode/u8_textprep.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ do_case_conv(int uv, uchar_t *u8s, uchar_t *s, int sz, boolean_t is_it_toupper)
for (i = 0; start_id < end_id; start_id++)
u8s[i++] = u8_toupper_final_tbl[uv][b3_base + start_id];
} else {
#ifdef U8_STRCMP_CI_LOWER
b3_tbl = u8_tolower_b3_tbl[uv][b2][b3].tbl_id;
if (b3_tbl == U8_TBL_ELEMENT_NOT_DEF)
return ((size_t)sz);
Expand All @@ -541,6 +542,9 @@ do_case_conv(int uv, uchar_t *u8s, uchar_t *s, int sz, boolean_t is_it_toupper)

for (i = 0; start_id < end_id; start_id++)
u8s[i++] = u8_tolower_final_tbl[uv][b3_base + start_id];
#else
__builtin_unreachable();
#endif
}

/*
Expand Down Expand Up @@ -1753,7 +1757,11 @@ do_norm_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, size_t n2,
s2last = s2 + n2;

is_it_toupper = flag & U8_TEXTPREP_TOUPPER;
#ifdef U8_STRCMP_CI_LOWER
is_it_tolower = flag & U8_TEXTPREP_TOLOWER;
#else
is_it_tolower = 0;
#endif
canonical_decomposition = flag & U8_CANON_DECOMP;
compatibility_decomposition = flag & U8_COMPAT_DECOMP;
canonical_composition = flag & U8_CANON_COMP;
Expand Down Expand Up @@ -1870,12 +1878,22 @@ u8_strcmp(const char *s1, const char *s2, size_t n, int flag, size_t uv,
if (flag == 0) {
flag = U8_STRCMP_CS;
} else {
f = flag & (U8_STRCMP_CS | U8_STRCMP_CI_UPPER |
U8_STRCMP_CI_LOWER);
#ifdef U8_STRCMP_CI_LOWER
f = flag & (U8_STRCMP_CS | U8_STRCMP_CI_UPPER
| U8_STRCMP_CI_LOWER);
#else
f = flag & (U8_STRCMP_CS | U8_STRCMP_CI_UPPER);
#endif
if (f == 0) {
flag |= U8_STRCMP_CS;
} else if (f != U8_STRCMP_CS && f != U8_STRCMP_CI_UPPER &&
f != U8_STRCMP_CI_LOWER) {
}
#ifdef U8_STRCMP_CI_LOWER
else if (f != U8_STRCMP_CS && f != U8_STRCMP_CI_UPPER &&
f != U8_STRCMP_CI_LOWER)
#else
else if (f != U8_STRCMP_CS && f != U8_STRCMP_CI_UPPER)
#endif
{
*errnum = EBADF;
flag = U8_STRCMP_CS;
}
Expand Down Expand Up @@ -1908,10 +1926,13 @@ u8_strcmp(const char *s1, const char *s2, size_t n, int flag, size_t uv,
if (flag == U8_STRCMP_CI_UPPER) {
return (do_case_compare(uv, (uchar_t *)s1, (uchar_t *)s2,
n1, n2, B_TRUE, errnum));
} else if (flag == U8_STRCMP_CI_LOWER) {
}
#ifdef U8_STRCMP_CI_LOWER
else if (flag == U8_STRCMP_CI_LOWER) {
return (do_case_compare(uv, (uchar_t *)s1, (uchar_t *)s2,
n1, n2, B_FALSE, errnum));
}
#endif

return (do_norm_compare(uv, (uchar_t *)s1, (uchar_t *)s2, n1, n2,
flag, errnum));
Expand Down Expand Up @@ -1945,11 +1966,13 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen,
return ((size_t)-1);
}

#ifdef U8_TEXTPREP_TOLOWER
f = flag & (U8_TEXTPREP_TOUPPER | U8_TEXTPREP_TOLOWER);
if (f == (U8_TEXTPREP_TOUPPER | U8_TEXTPREP_TOLOWER)) {
*errnum = EBADF;
return ((size_t)-1);
}
#endif

f = flag & (U8_CANON_DECOMP | U8_COMPAT_DECOMP | U8_CANON_COMP);
if (f && f != U8_TEXTPREP_NFD && f != U8_TEXTPREP_NFC &&
Expand All @@ -1974,7 +1997,11 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen,
do_not_ignore_null = !(flag & U8_TEXTPREP_IGNORE_NULL);
do_not_ignore_invalid = !(flag & U8_TEXTPREP_IGNORE_INVALID);
is_it_toupper = flag & U8_TEXTPREP_TOUPPER;
#ifdef U8_TEXTPREP_TOLOWER
is_it_tolower = flag & U8_TEXTPREP_TOLOWER;
#else
is_it_tolower = 0;
#endif

ret_val = 0;

Expand Down

0 comments on commit 60c202c

Please sign in to comment.