diff --git a/include/boost/multi_index/detail/rnd_index_node.hpp b/include/boost/multi_index/detail/rnd_index_node.hpp index 782fdd8..9f76eed 100644 --- a/include/boost/multi_index/detail/rnd_index_node.hpp +++ b/include/boost/multi_index/detail/rnd_index_node.hpp @@ -1,4 +1,4 @@ -/* Copyright 2003-2018 Joaquin M Lopez Munoz. +/* Copyright 2003-2021 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) @@ -169,6 +169,25 @@ struct random_access_index_node_impl } } + static ptr_pointer gather_nulls( + ptr_pointer pbegin,ptr_pointer pend,ptr_pointer x) + { + for(ptr_pointer p=pbegin;p!=x;++p){ + if(*p){ + *pbegin=*p; + (*pbegin)->up()=pbegin; + ++pbegin; + } + } + for(ptr_pointer p=pend;p!=x;){ + if(*--p){ + *--pend=*p; + (*pend)->up()=pend; + } + } + return pbegin; + } + private: ptr_pointer up_; }; diff --git a/include/boost/multi_index/random_access_index.hpp b/include/boost/multi_index/random_access_index.hpp index ee5b715..183848f 100644 --- a/include/boost/multi_index/random_access_index.hpp +++ b/include/boost/multi_index/random_access_index.hpp @@ -1140,9 +1140,21 @@ private: template void internal_splice(iterator position,Iterator first,Iterator last) { - index_node_type* pn=position.get_node(); - while(first!=last){ - relocate(pn,static_cast((first++).get_node())); + /* null out [first, last) positions in ptrs array */ + + for(Iterator it=first;it!=last;++it){ + *(static_cast(it.get_node())->up())=0; + } + + node_impl_ptr_pointer pp=node_impl_type::gather_nulls( + ptrs.begin(),ptrs.end(), + static_cast(position.get_node())->up()); + + /* relink [first, last) */ + + for(Iterator it=first;it!=last;++it,++pp){ + *pp=static_cast(it.get_node()); + (*pp)->up()=pp; } }