orxfun / orx-split-vec

An efficient constant access time vector with dynamic capacity and pinned elements.
https://crates.io/crates/orx-split-vec
MIT License
2 stars 2 forks source link

Extend Performance Optimization #21

Open orxfun opened 9 months ago

orxfun commented 9 months ago

Current Extend implementation of the SplitVec is only for convenience rather than for performance. The implementation looks as below

impl<T, G> Extend<T> for SplitVec<T, G>
where
    G: Growth,
{
    fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
        for x in iter {
            self.push(x);
        }
    }
}

std::vec::Vec implementation, however, uses is optimized with special extend traits. With some book keeping and with the use of size hints, SplitVec can directly call std::vec::Vec::extend method and indirectly utilize these optimizations rather than pushing each element one after the other.