From 745aabcfd55801551ed6c95492b9c5f8a447e5a2 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 14 May 2018 22:55:17 +0200 Subject: [PATCH] Factorisation of all calls to GET_CMP within the sort functions to a single function. --- m-algo.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/m-algo.h b/m-algo.h index 2ceb269c..31701d93 100644 --- a/m-algo.h +++ b/m-algo.h @@ -337,6 +337,9 @@ #define ALGOI_SORT_DEF(name, container_t, cont_oplist, type_t, type_oplist, it_t) \ \ + static inline int M_C(name,_sort_cmp)(const type_t*a,const type_t*b) {\ + return M_GET_CMP type_oplist(*a, *b); \ + } \ static inline bool \ M_C(name, _sort_p)(const container_t l) \ { \ @@ -348,7 +351,7 @@ while (!M_GET_IT_END_P cont_oplist (it2)) { \ const type_t *ref1 = M_GET_IT_CREF cont_oplist (it1); \ const type_t *ref2 = M_GET_IT_CREF cont_oplist (it2); \ - if (!(M_GET_CMP type_oplist (*ref1, *ref2) <= 0)) { \ + if (!(M_C(name, _sort_cmp)(ref1, ref2) <= 0)) { \ return false; \ } \ M_GET_IT_SET cont_oplist (it1, it2); \ @@ -363,9 +366,6 @@ /* - a selection sort */ \ M_IF_METHOD(SORT, cont_oplist)( \ /* optimized sort for container */ \ - static inline int M_C(name,_sort_cmp)(const type_t*a,const type_t*b) {\ - return M_GET_CMP type_oplist(*a, *b); \ - } \ static inline void M_C(name, _sort)(container_t l) \ { \ M_GET_SORT cont_oplist(l, M_C(name, _sort_cmp)); \ @@ -387,8 +387,8 @@ M_GET_IT_SET cont_oplist (it21, it1); \ M_GET_IT_PREVIOUS cont_oplist (it2); \ while (!M_GET_IT_END_P cont_oplist (it2) \ - && !(M_GET_CMP type_oplist (*M_GET_IT_CREF cont_oplist (it2), \ - x)) <= 0) { \ + && !(M_C(name, _sort_cmp)(M_GET_IT_CREF cont_oplist (it2), \ + &x)) <= 0) { \ memcpy(M_GET_IT_REF cont_oplist (it21), \ M_GET_IT_CREF cont_oplist (it2), sizeof (type_t) ); \ M_GET_IT_SET cont_oplist (it21, it2); \ @@ -412,8 +412,8 @@ for(M_GET_IT_NEXT cont_oplist (it2) ; \ !M_GET_IT_END_P cont_oplist (it2); \ M_GET_IT_NEXT cont_oplist (it2)) { \ - if (M_GET_CMP type_oplist (*M_GET_IT_CREF cont_oplist (it2), \ - *M_GET_IT_CREF cont_oplist (it_min)) < 0) { \ + if (M_C(name, _sort_cmp) (M_GET_IT_CREF cont_oplist (it2), \ + M_GET_IT_CREF cont_oplist (it_min)) < 0) { \ M_GET_IT_SET cont_oplist (it_min, it2); \ } \ } \ @@ -443,7 +443,7 @@ && !M_GET_IT_END_P cont_oplist (itDst)) { \ const type_t *objSrc = M_GET_IT_CREF cont_oplist (itSrc); \ const type_t *objDst = M_GET_IT_CREF cont_oplist (itDst); \ - int cmp = M_GET_CMP type_oplist (*objDst, *objSrc); \ + int cmp = M_C(name, _sort_cmp)(objDst, objSrc); \ if (cmp == 0) { \ M_GET_IT_NEXT cont_oplist (itSrc); \ M_GET_IT_NEXT cont_oplist (itDst); \ @@ -480,7 +480,7 @@ && !M_GET_IT_END_P cont_oplist (itDst)) { \ const type_t *objSrc = M_GET_IT_CREF cont_oplist (itSrc); \ const type_t *objDst = M_GET_IT_CREF cont_oplist (itDst); \ - int cmp = M_GET_CMP type_oplist (*objDst, *objSrc); \ + int cmp = M_C(name, _sort_cmp)(objDst, objSrc); \ if (cmp == 0) { \ /* Keep it */ \ M_GET_IT_NEXT cont_oplist (itSrc); \