diff --git a/src/util/list_fn.h b/src/util/list_fn.h index ccbd3b870..66680bfec 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; + } } /**