mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-29 05:12:41 +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;
|
struct proc_hash_entry *phe;
|
||||||
static char first_run = 1;
|
static char first_run = 1;
|
||||||
|
int bucket;
|
||||||
|
|
||||||
/* better make sure all next pointers are zero upon first access */
|
/* better make sure all next pointers are zero upon first access */
|
||||||
if (first_run) {
|
if (first_run) {
|
||||||
@ -54,17 +55,14 @@ static void hash_process(struct process *p)
|
|||||||
first_run = 0;
|
first_run = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the bucket head */
|
/* get the bucket index */
|
||||||
phe = &proc_hash_table[p->pid % 256];
|
bucket = p->pid % 256;
|
||||||
|
|
||||||
/* find the bucket's end */
|
/* insert a new element on bucket's top */
|
||||||
while (phe->next)
|
phe = malloc(sizeof(struct proc_hash_entry));
|
||||||
phe = phe->next;
|
phe->proc = p;
|
||||||
|
phe->next = proc_hash_table[bucket].next;
|
||||||
/* append process */
|
proc_hash_table[bucket].next = phe;
|
||||||
phe->next = malloc(sizeof(struct proc_hash_entry));
|
|
||||||
memset(phe->next, 0, sizeof(struct proc_hash_entry));
|
|
||||||
phe->next->proc = p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unhash_process(struct process *p)
|
static void unhash_process(struct process *p)
|
||||||
|
Loading…
Reference in New Issue
Block a user