diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-30 15:58:02 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-30 15:58:02 +0100 |
commit | fe69a42861ad1ff52c01f6e7c1b7df54b0c8bd7a (patch) | |
tree | 2281772d623932355b8efad5fe20cc026046ffd8 | |
parent | 4895d62cd9d69476df343f4588f8747143c783f1 (diff) | |
download | rspamd-fe69a42861ad1ff52c01f6e7c1b7df54b0c8bd7a.tar.gz rspamd-fe69a42861ad1ff52c01f6e7c1b7df54b0c8bd7a.zip |
[Minor] Optimize memory layout for task
-rw-r--r-- | src/libserver/task.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/libserver/task.c b/src/libserver/task.c index f960829fc..e2fcdb2d6 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -66,8 +66,20 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg, struct ev_loop *event_loop) { struct rspamd_task *new_task; + rspamd_mempool_t *task_pool; + guint flags = 0; - new_task = g_malloc0 (sizeof (struct rspamd_task)); + if (pool == NULL) { + task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "task"); + flags |= RSPAMD_TASK_FLAG_OWN_POOL; + } + else { + task_pool = pool; + } + + new_task = rspamd_mempool_alloc0 (task_pool, sizeof (struct rspamd_task)); + new_task->task_pool = task_pool; + new_task->flags = flags; new_task->worker = worker; new_task->lang_det = lang_det; @@ -93,15 +105,6 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg, new_task->task_timestamp = ev_time (); new_task->time_real_finish = NAN; - if (pool == NULL) { - new_task->task_pool = - rspamd_mempool_new (rspamd_mempool_suggest_size (), "task"); - new_task->flags |= RSPAMD_TASK_FLAG_OWN_POOL; - } - else { - new_task->task_pool = pool; - } - new_task->request_headers = kh_init (rspamd_req_headers_hash); new_task->sock = -1; new_task->flags |= (RSPAMD_TASK_FLAG_MIME); @@ -293,8 +296,6 @@ rspamd_task_free (struct rspamd_task *task) if (task->flags & RSPAMD_TASK_FLAG_OWN_POOL) { rspamd_mempool_delete (task->task_pool); } - - g_free (task); } } |