mirror of
https://github.com/adulau/aha.git
synced 2024-12-27 11:16:11 +00:00
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>
This commit is contained in:
parent
e30618cbd1
commit
995e4286a0
1 changed files with 1 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue