mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-27 20:44:56 +00:00
improve hash_process() by inserting at bucket's top instead of bottom
This commit is contained in:
parent
0406000351
commit
36f6af922b
18
src/top.c
18
src/top.c
@ -47,6 +47,7 @@ static void hash_process(struct process *p)
|
||||
{
|
||||
struct proc_hash_entry *phe;
|
||||
static char first_run = 1;
|
||||
int bucket;
|
||||
|
||||
/* better make sure all next pointers are zero upon first access */
|
||||
if (first_run) {
|
||||
@ -54,17 +55,14 @@ static void hash_process(struct process *p)
|
||||
first_run = 0;
|
||||
}
|
||||
|
||||
/* get the bucket head */
|
||||
phe = &proc_hash_table[p->pid % 256];
|
||||
/* get the bucket index */
|
||||
bucket = p->pid % 256;
|
||||
|
||||
/* find the bucket's end */
|
||||
while (phe->next)
|
||||
phe = phe->next;
|
||||
|
||||
/* append process */
|
||||
phe->next = malloc(sizeof(struct proc_hash_entry));
|
||||
memset(phe->next, 0, sizeof(struct proc_hash_entry));
|
||||
phe->next->proc = p;
|
||||
/* insert a new element on bucket's top */
|
||||
phe = malloc(sizeof(struct proc_hash_entry));
|
||||
phe->proc = p;
|
||||
phe->next = proc_hash_table[bucket].next;
|
||||
proc_hash_table[bucket].next = phe;
|
||||
}
|
||||
|
||||
static void unhash_process(struct process *p)
|
||||
|
Loading…
Reference in New Issue
Block a user