From 76c35090ce15f720a833b93a9f1ce5514710570b Mon Sep 17 00:00:00 2001 From: Lukasz Stanislawski Date: Thu, 19 Jul 2018 12:08:19 +0200 Subject: process: micro optimization Change-Id: Ib21b5172763663d83e160016f645e276a8c0ad88 --- src/proc-scanner.c | 12 +++++------- src/process.c | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/proc-scanner.c b/src/proc-scanner.c index 2798e42..b2fdf9e 100644 --- a/src/proc-scanner.c +++ b/src/proc-scanner.c @@ -52,11 +52,11 @@ void proctab_resize(struct proctab *tab, int new_max) tab->max = new_max; } -void proctab_append(struct proctab *tab, struct process *proc) +void proctab_move_back(struct proctab *tab, struct process *proc) { if (tab->size >= tab->max) proctab_resize(tab, tab->max *= 2); - tab->processes[tab->size++] = *proc; + process_move(&tab->processes[tab->size++],proc); } void proctab_reset(struct proctab *tab) @@ -142,15 +142,13 @@ static bool _proc_scanner_read_pid(int pid, void *user_data) if (!proc) { process_init(pid, &proc_new); proc = &proc_new; - } else { - process_move(&proc_new, proc); } - if (process_update(&proc_new) != 0) { - process_shutdown(&proc_new); + if (process_update(proc) != 0) { + process_shutdown(proc); return true; } - proctab_append(&scanner->current, &proc_new); + proctab_move_back(&scanner->current, proc); return true; } diff --git a/src/process.c b/src/process.c index e5f7753..70f4bb0 100644 --- a/src/process.c +++ b/src/process.c @@ -78,11 +78,11 @@ void process_shutdown(struct process *proc) if (!proc) return; free(proc->appid); free(proc->exe); + memset(proc, 0x0, sizeof(struct process)); } void process_move(struct process *dst, struct process *src) { - process_shutdown(dst); memcpy(dst, src, sizeof(struct process)); src->appid = NULL; src->exe = NULL; -- cgit v1.2.3