]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Optimize memory layout for task
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Sep 2019 14:58:02 +0000 (15:58 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Sep 2019 14:58:02 +0000 (15:58 +0100)
src/libserver/task.c

index f960829fc51e3e0a5953a7cec49362bf4b2cf6a7..e2fcdb2d6beadfe72df40764a1077fce18ea5e85 100644 (file)
@@ -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);
        }
 }