From 6c59a7213763dfe2859c7cfe6683711700fda978 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Wed, 28 Jul 2010 02:36:01 +0200 Subject: Stop looking in the hash table after the first match. There should be only one entry anyway. This reduces the average lookup time when there are hash collisions roughly by half. --- ncr-limits.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ncr-limits.c b/ncr-limits.c index 3dcb9cc..4d36c4f 100644 --- a/ncr-limits.c +++ b/ncr-limits.c @@ -140,6 +140,7 @@ int ret; mutex_unlock(&user_limit_mutex); return -EPERM; } + break; } } @@ -175,6 +176,7 @@ int ret; ret = -EPERM; goto restore_user; } + break; } } @@ -203,8 +205,10 @@ int ret; restore_user: mutex_lock(&user_limit_mutex); hlist_for_each_entry(uitem, pos, user_head, hlist) { - if (uitem->uid == uid) + if (uitem->uid == uid) { atomic_dec(&uitem->cnt[type]); + break; + } } mutex_unlock(&user_limit_mutex); return ret; @@ -223,6 +227,7 @@ struct hlist_node *pos; hlist_for_each_entry(uitem, pos, hhead, hlist) { if (uitem->uid == uid) { atomic_dec(&uitem->cnt[type]); + break; } } mutex_unlock(&user_limit_mutex); @@ -233,6 +238,7 @@ struct hlist_node *pos; hlist_for_each_entry(pitem, pos, hhead, hlist) { if (pitem->pid == pid) { atomic_dec(&pitem->cnt[type]); + break; } } mutex_unlock(&process_limit_mutex); -- cgit