Skip to content

Commit

Permalink
[PATCH] Use unsigned int types for a faster bsearch
Browse files Browse the repository at this point in the history
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@cosmosbay.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Eric Dumazet authored and Linus Torvalds committed Mar 25, 2006
1 parent 34f361a commit d74beb9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,15 +1363,15 @@ static void groups_sort(struct group_info *group_info)
/* 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;

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;
Expand Down

0 comments on commit d74beb9

Please sign in to comment.