[PATCH] Use unsigned int types for a faster bsearch

From: Eric Dumazet
Date: Mon Mar 20 2006 - 14:07:43 EST


This patch avoids arithmetic on 'signed' types that are slower than 'unsigned'. This saves space and cpu cycles.

size of kernel/sys.o before the patch (gcc-3.4.5)

text data bss dec hex filename
10924 252 4 11180 2bac kernel/sys.o

size of kernel/sys.o after the patch
text data bss dec hex filename
10903 252 4 11159 2b97 kernel/sys.o

I noticed that gcc-4.1.0 (from Fedora Core 5) even uses idiv instruction for (a+b)/2 if a and b are signed.

Signed-off-by: Eric Dumazet <dada1@xxxxxxxxxxxxx>

--- a/kernel/sys.c 2006-03-20 18:42:41.000000000 +0100
+++ b/kernel/sys.c 2006-03-20 19:00:43.000000000 +0100
@@ -1375,7 +1375,7 @@
/* a simple bsearch */
int groups_search(struct group_info *group_info, gid_t grp)
{
- int left, right;
+ unsigned int left, right;

if (!group_info)
return 0;
@@ -1383,7 +1383,7 @@
left = 0;
right = group_info->ngroups;
while (left < right) {
- int mid = (left+right)/2;
+ unsigned int mid = (left+right)/2;
int cmp = grp - GROUP_AT(group_info, mid);
if (cmp > 0)
left = mid + 1;