Skip to content

Commit

Permalink
lib/sort.c optimization
Browse files Browse the repository at this point in the history
Hello, I fixed and tested a small bug in lib/sort.c file, heap sort
function.

The fix avoids unnecessary swap of contents when i is 0 (saves few loads
and stores), which happens every time sort function is called.  I felt the
fix is worth bringing it to your attention given the importance and
frequent use of the sort function.

Acked-by: Matt Mackall <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Subbaiah Venkata authored and Linus Torvalds committed Oct 17, 2007
1 parent e30618c commit 995e428
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void sort(void *base, size_t num, size_t size,
}

/* sort */
for (i = n - size; i >= 0; i -= size) {
for (i = n - size; i > 0; i -= size) {
swap(base, base + i, size);
for (r = 0; r * 2 + size < i; r = c) {
c = r * 2 + size;
Expand Down

0 comments on commit 995e428

Please sign in to comment.