From 1aca1d2d776c0dc41ef508a34bbdd970a99c7658 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Thu, 26 Sep 2013 18:03:34 -0700 Subject: [PATCH] refactor(list): improve append function Signed-off-by: Leonardo de Moura --- src/util/list_fn.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/util/list_fn.h b/src/util/list_fn.h index ccbd3b8708..66680bfec2 100644 --- a/src/util/list_fn.h +++ b/src/util/list_fn.h @@ -86,10 +86,21 @@ std::pair, list> split_reverse_second(list const & l) { */ template list append(list const & l1, list const & l2) { - buffer tmp; - to_buffer(l1, tmp); - to_buffer(l2, tmp); - return to_list(tmp.begin(), tmp.end()); + if (!l1) { + return l2; + } else if (!l2) { + return l1; + } else { + buffer tmp; + list r = l2; + to_buffer(l1, tmp); + unsigned i = tmp.size(); + while (i > 0) { + --i; + r = cons(tmp[i], r); + } + return r; + } } /**