Commit 995e4286a047b32aebf8ce540908edb7fbd93f76

Authored by Subbaiah Venkata
Committed by Linus Torvalds
1 parent e30618cbd1

lib/sort.c optimization

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 <mpm@selenic.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 1 additions and 1 deletions Side-by-side Diff

... ... @@ -67,7 +67,7 @@
67 67 }
68 68  
69 69 /* sort */
70   - for (i = n - size; i >= 0; i -= size) {
  70 + for (i = n - size; i > 0; i -= size) {
71 71 swap(base, base + i, size);
72 72 for (r = 0; r * 2 + size < i; r = c) {
73 73 c = r * 2 + size;