Skip to contentSkip to conversation

lib/sort.c, 2.6.22 kernel

PATCH In review Subbaiah Venkata 3 participants 3 messages Aug 8, 2007 – Sep 25, 2007 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/sort.c, 2.6.22 kernel

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.

Thank you all.

==================================================================

lib/sort.c +1 -1
index 9615678..6abbaf3 100644
@@ -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;
#1 lore raw
Quoted 8 lines · Subbaiah Venkata

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.

Would you like to resubmit this? Please do ;) (I am hinting at Documentation/SubmittingPatches too..)

Quoted 15 lines

==================================================================

lib/sort.c +1 -1
index 9615678..6abbaf3 100644
@@ -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;
#2 lore raw
Quoted 6 lines · Jan Engelhardt
Quoted 4 lines · Subbaiah Venkata

Hello, I fixed and tested a small bug in lib/sort.c file, heap sort function.

Quoted 7 lines
Quoted 4 lines

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.

Would you like to resubmit this? Please do ;) (I am hinting at Documentation/SubmittingPatches too..)

This is in -mm already.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.