diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-06-02 13:06:21 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-06-02 13:06:21 +0100 |
commit | 92883774725f7ac936e50239ee4b50e9acaa10cc (patch) | |
tree | 0a7fc502a95b4b7a31ed5536e5754787ac09fcd3 /src/libmime/mime_encoding.c | |
parent | 44aa58ddceed5d33c0395d42335ce71e1c865e96 (diff) | |
download | rspamd-92883774725f7ac936e50239ee4b50e9acaa10cc.tar.gz rspamd-92883774725f7ac936e50239ee4b50e9acaa10cc.zip |
[Minor] Add fast paths for utf8 conversions
Diffstat (limited to 'src/libmime/mime_encoding.c')
-rw-r--r-- | src/libmime/mime_encoding.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libmime/mime_encoding.c b/src/libmime/mime_encoding.c index e97c390b8..36c37f10b 100644 --- a/src/libmime/mime_encoding.c +++ b/src/libmime/mime_encoding.c @@ -255,12 +255,26 @@ rspamd_mime_detect_charset (const rspamd_ftok_t *in, rspamd_mempool_t *pool) gchar *ret = NULL, *h, *t; struct rspamd_charset_substitution *s; const gchar *cset; + rspamd_ftok_t utf8_tok; UErrorCode uc_err = U_ZERO_ERROR; if (sub_hash == NULL) { rspamd_mime_encoding_substitute_init (); } + /* Fast path */ + RSPAMD_FTOK_ASSIGN (&utf8_tok, "utf-8"); + + if (rspamd_ftok_casecmp (in, &utf8_tok) == 0) { + return UTF8_CHARSET; + } + + RSPAMD_FTOK_ASSIGN (&utf8_tok, "utf8"); + + if (rspamd_ftok_casecmp (in, &utf8_tok) == 0) { + return UTF8_CHARSET; + } + ret = rspamd_mempool_ftokdup (pool, in); rspamd_charset_normalize (ret); @@ -320,6 +334,21 @@ rspamd_mime_text_to_utf8 (rspamd_mempool_t *pool, UErrorCode uc_err = U_ZERO_ERROR; UConverter *utf8_converter; struct rspamd_charset_converter *conv; + rspamd_ftok_t cset_tok; + + /* Check if already utf8 */ + RSPAMD_FTOK_FROM_STR (&cset_tok, in_enc); + + if (rspamd_mime_charset_utf_check (&cset_tok, input, len, + FALSE)) { + d = rspamd_mempool_alloc (pool, len); + memcpy (d, input, len); + if (olen) { + *olen = len; + } + + return d; + } conv = rspamd_mime_get_converter_cached (in_enc, pool, TRUE, &uc_err); utf8_converter = rspamd_get_utf8_converter (); |