diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-05-11 19:06:41 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-05-11 19:06:41 +0100 |
commit | 25db12ee3fce3a41c1fd907373ead67015cef6ed (patch) | |
tree | 17bc90713626f1fdac01b4ec4f6dfca6bc30ee8d /src | |
parent | 8105992157606e77f0e88968a40aaf8e528c70d8 (diff) | |
download | rspamd-25db12ee3fce3a41c1fd907373ead67015cef6ed.tar.gz rspamd-25db12ee3fce3a41c1fd907373ead67015cef6ed.zip |
[Feature] Optimize alignment to speed up hashing
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/shingles.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c index 04a9975bc..3e238fa5c 100644 --- a/src/libutil/shingles.c +++ b/src/libutil/shingles.c @@ -95,6 +95,8 @@ rspamd_shingles_generate (GArray *input, } else { guint64 res[SHINGLES_WINDOW * RSPAMD_SHINGLE_SIZE]; + guint64 RSPAMD_ALIGNED(32) tmpbuf[16]; + guint rlen; if (alg == RSPAMD_SHINGLES_XXHASH) { ht = RSPAMD_CRYPTOBOX_XXHASH64; @@ -117,11 +119,20 @@ rspamd_shingles_generate (GArray *input, word = &g_array_index (input, rspamd_ftok_t, beg); /* Insert the last element to the pipe */ + if (word->len >= sizeof (tmpbuf)) { + rlen = sizeof (tmpbuf); + memcpy (tmpbuf, word->begin, rlen); + } + else { + rlen = word->len / sizeof (guint64) + 1; + memset (tmpbuf, 0, rlen * sizeof (guint64)); + memcpy (tmpbuf, word->begin, word->len); + } + res[j * SHINGLES_WINDOW + SHINGLES_WINDOW - 1] = rspamd_cryptobox_fast_hash_specific (ht, - word->begin, word->len, + tmpbuf,rlen * sizeof (guint64), *(guint64 *)keys[j]); - val = 0; for (k = 0; k < SHINGLES_WINDOW; k ++) { val ^= res[j * SHINGLES_WINDOW + k]; |