From 1925c90812b0c005c764667f154f827d3cfe9ff5 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Wed, 3 May 2017 00:57:05 +0200 Subject: [PATCH] Optimize _map_reduce. --- m-algo.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/m-algo.h b/m-algo.h index 6dc8d676..85d10fc7 100644 --- a/m-algo.h +++ b/m-algo.h @@ -49,6 +49,7 @@ /* Extract a subset of a container to fill in another container. USAGE: ALGO_EXTRACT(containerDest, containerDestOplist, containerSrc, containerSrcOplist, func[, extra arguments of function]) */ +// TODO: without 'func' parameter, extract all. #define ALGO_EXTRACT(contD, contDop, contS, contSop, ...) \ M_IF_NARGS_EQ1(__VA_ARGS__) \ (ALGOI_EXTRACT(contD, contDop, contS, contSop, __VA_ARGS__), \ @@ -65,7 +66,7 @@ ALGOI_REDUCE_MAP_ARG(dest, cont, contOp, __VA_ARGS__) ) ) -/* Initialize a container by a variable array list. +/* Initialize & set a container with a variable array list. USAGE: ALGO_INIT_VA(container, containerOplist, param1[, param2[, ...]]) */ #define ALGO_INIT_VA(dest, contOp, ...) do { \ M_GET_INIT contOp (dest); \ @@ -152,11 +153,11 @@ type_t tmp; \ M_GET_INIT type_oplist (tmp); \ for M_EACH(item, l, cont_oplist) { \ - m(tmp, *item); \ - if (initDone) \ + if (initDone) { \ + m(tmp, *item); \ r(*dest, tmp); \ - else { \ - M_GET_SET type_oplist (*dest, tmp); \ + } else { \ + m(*dest, *item); \ initDone = true; \ } \ } \