Skip to content

prepend! allocates when X is empty even when there's capacity #56026

@dpinol

Description

@dpinol

This does not report any allocation in julia 1.10, but reports 2 allocations in the first prepend! in julia 1.11rc4 & julia 1.12 master.
I guess it shouldn't allocate because x has enough capacity.

const x=Vector{Int}(undef, 1000)
empty!(x) 
@time prepend!(x, 10)
@time prepend!(x, 10)

0.000007 seconds (2 allocations: 16.844 KiB)
  0.000001 seconds

The same happens with insert!(x,1, 10), which is called twice by the first insertion into an SparseArray

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions