refactor(list): improve append function

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-09-26 18:03:34 -07:00
parent 24c173a519
commit 1aca1d2d77

View file

@ -86,10 +86,21 @@ std::pair<list<T>, list<T>> split_reverse_second(list<T> const & l) {
*/
template<typename T>
list<T> append(list<T> const & l1, list<T> const & l2) {
buffer<T> 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<T> tmp;
list<T> r = l2;
to_buffer(l1, tmp);
unsigned i = tmp.size();
while (i > 0) {
--i;
r = cons(tmp[i], r);
}
return r;
}
}
/**