From 04ff9c2548eb4d8b8a59db23f7212c7a8cdd25aa Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 22 Jan 2012 22:53:57 +0100 Subject: [PATCH] Simplify our insertion sort implementation No functional change. Signed-off-by: Marco Costalba --- src/types.h | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/types.h b/src/types.h index 601d0703..8ce7dab5 100644 --- a/src/types.h +++ b/src/types.h @@ -485,23 +485,18 @@ inline const std::string square_to_string(Square s) { /// Our insertion sort implementation, works with pointers and iterators and is /// guaranteed to be stable, as is needed. template -void sort(K firstMove, K lastMove) +void sort(K first, K last) { - T value; - K cur, p, d; - - if (firstMove != lastMove) - for (cur = firstMove + 1; cur != lastMove; cur++) - { - p = d = cur; - value = *p--; - if (*p < value) - { - do *d = *p; - while (--d != firstMove && *--p < value); - *d = value; - } - } + T tmp; + K p, q; + + for (p = first + 1; p < last; p++) + { + tmp = *p; + for (q = p; q != first && *(q-1) < tmp; --q) + *q = *(q-1); + *q = tmp; + } } #endif // !defined(TYPES_H_INCLUDED) -- 2.39.2