From f229bc0caaeda22bfbea9a5f9605b01c69e14cbc Mon Sep 17 00:00:00 2001 From: Gerhard Aigner Date: Mon, 23 Dec 2024 07:48:32 +0100 Subject: [PATCH] Improve deleteat!(x,::Integer) We only need to remove one element from a ChainedVector and can therefore special case the fact that if this element is a single entry in a chunk the chunk can be removed completely. This reliefs us from the slow `cleanup!()` call. --- src/chainedvector.jl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/chainedvector.jl b/src/chainedvector.jl index a5dd69e..3b08b4f 100644 --- a/src/chainedvector.jl +++ b/src/chainedvector.jl @@ -577,12 +577,19 @@ end Base.@propagate_inbounds function Base.deleteat!(A::ChainedVector, i::Integer) @boundscheck checkbounds(A, i) chunk, ix = index(A, i) - deleteat!(A.arrays[chunk], ix) - for j = chunk:length(A.inds) + lastchunk = length(A.inds) + if length(A.arrays[chunk]) == 1 + deleteat!(A.arrays, chunk) + deleteat!(A.inds, chunk) + lastchunk -= 1 + resize!(A.arrays, lastchunk) + resize!(A.inds, lastchunk) + else + deleteat!(A.arrays[chunk], ix) + end + for j = chunk:lastchunk @inbounds A.inds[j] -= 1 end - # check if we should remove an empty chunk - cleanup!(A) return A end