mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
unicode: cache the normalization tables in struct unicode_map
Instead of repeatedly looking up the version add pointers to the NFD and NFD+CF tables to struct unicode_map, and pass a unicode_map plus index to the functions using the normalization tables. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
This commit is contained in:
committed by
Gabriel Krisman Bertazi
parent
fbc59d6505
commit
6ca99ce756
@@ -5,16 +5,13 @@
|
||||
#include <linux/slab.h>
|
||||
#include <linux/parser.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/unicode.h>
|
||||
#include <linux/stringhash.h>
|
||||
|
||||
#include "utf8n.h"
|
||||
|
||||
int utf8_validate(const struct unicode_map *um, const struct qstr *str)
|
||||
{
|
||||
const struct utf8data *data = utf8nfdi(um->version);
|
||||
|
||||
if (utf8nlen(data, str->name, str->len) < 0)
|
||||
if (utf8nlen(um, UTF8_NFDI, str->name, str->len) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
@@ -23,14 +20,13 @@ EXPORT_SYMBOL(utf8_validate);
|
||||
int utf8_strncmp(const struct unicode_map *um,
|
||||
const struct qstr *s1, const struct qstr *s2)
|
||||
{
|
||||
const struct utf8data *data = utf8nfdi(um->version);
|
||||
struct utf8cursor cur1, cur2;
|
||||
int c1, c2;
|
||||
|
||||
if (utf8ncursor(&cur1, data, s1->name, s1->len) < 0)
|
||||
if (utf8ncursor(&cur1, um, UTF8_NFDI, s1->name, s1->len) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (utf8ncursor(&cur2, data, s2->name, s2->len) < 0)
|
||||
if (utf8ncursor(&cur2, um, UTF8_NFDI, s2->name, s2->len) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
do {
|
||||
@@ -50,14 +46,13 @@ EXPORT_SYMBOL(utf8_strncmp);
|
||||
int utf8_strncasecmp(const struct unicode_map *um,
|
||||
const struct qstr *s1, const struct qstr *s2)
|
||||
{
|
||||
const struct utf8data *data = utf8nfdicf(um->version);
|
||||
struct utf8cursor cur1, cur2;
|
||||
int c1, c2;
|
||||
|
||||
if (utf8ncursor(&cur1, data, s1->name, s1->len) < 0)
|
||||
if (utf8ncursor(&cur1, um, UTF8_NFDICF, s1->name, s1->len) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (utf8ncursor(&cur2, data, s2->name, s2->len) < 0)
|
||||
if (utf8ncursor(&cur2, um, UTF8_NFDICF, s2->name, s2->len) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
do {
|
||||
@@ -81,12 +76,11 @@ int utf8_strncasecmp_folded(const struct unicode_map *um,
|
||||
const struct qstr *cf,
|
||||
const struct qstr *s1)
|
||||
{
|
||||
const struct utf8data *data = utf8nfdicf(um->version);
|
||||
struct utf8cursor cur1;
|
||||
int c1, c2;
|
||||
int i = 0;
|
||||
|
||||
if (utf8ncursor(&cur1, data, s1->name, s1->len) < 0)
|
||||
if (utf8ncursor(&cur1, um, UTF8_NFDICF, s1->name, s1->len) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
do {
|
||||
@@ -105,11 +99,10 @@ EXPORT_SYMBOL(utf8_strncasecmp_folded);
|
||||
int utf8_casefold(const struct unicode_map *um, const struct qstr *str,
|
||||
unsigned char *dest, size_t dlen)
|
||||
{
|
||||
const struct utf8data *data = utf8nfdicf(um->version);
|
||||
struct utf8cursor cur;
|
||||
size_t nlen = 0;
|
||||
|
||||
if (utf8ncursor(&cur, data, str->name, str->len) < 0)
|
||||
if (utf8ncursor(&cur, um, UTF8_NFDICF, str->name, str->len) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
for (nlen = 0; nlen < dlen; nlen++) {
|
||||
@@ -128,12 +121,11 @@ EXPORT_SYMBOL(utf8_casefold);
|
||||
int utf8_casefold_hash(const struct unicode_map *um, const void *salt,
|
||||
struct qstr *str)
|
||||
{
|
||||
const struct utf8data *data = utf8nfdicf(um->version);
|
||||
struct utf8cursor cur;
|
||||
int c;
|
||||
unsigned long hash = init_name_hash(salt);
|
||||
|
||||
if (utf8ncursor(&cur, data, str->name, str->len) < 0)
|
||||
if (utf8ncursor(&cur, um, UTF8_NFDICF, str->name, str->len) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
while ((c = utf8byte(&cur))) {
|
||||
@@ -149,11 +141,10 @@ EXPORT_SYMBOL(utf8_casefold_hash);
|
||||
int utf8_normalize(const struct unicode_map *um, const struct qstr *str,
|
||||
unsigned char *dest, size_t dlen)
|
||||
{
|
||||
const struct utf8data *data = utf8nfdi(um->version);
|
||||
struct utf8cursor cur;
|
||||
ssize_t nlen = 0;
|
||||
|
||||
if (utf8ncursor(&cur, data, str->name, str->len) < 0)
|
||||
if (utf8ncursor(&cur, um, UTF8_NFDI, str->name, str->len) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
for (nlen = 0; nlen < dlen; nlen++) {
|
||||
@@ -180,7 +171,17 @@ struct unicode_map *utf8_load(unsigned int version)
|
||||
if (!um)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
um->version = version;
|
||||
um->ntab[UTF8_NFDI] = utf8nfdi(version);
|
||||
if (!um->ntab[UTF8_NFDI])
|
||||
goto out_free_um;
|
||||
um->ntab[UTF8_NFDICF] = utf8nfdicf(version);
|
||||
if (!um->ntab[UTF8_NFDICF])
|
||||
goto out_free_um;
|
||||
return um;
|
||||
|
||||
out_free_um:
|
||||
kfree(um);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
EXPORT_SYMBOL(utf8_load);
|
||||
|
||||
|
Reference in New Issue
Block a user