Skip to content

Commit 05182dc

Browse files
oscardssmithKristofferC
authored andcommitted
make _unsetindex fast for isbits eltype (#56364)
fixes #56359 (comment) ``` using Plots function f(n) a = Vector{Int}(undef, n) s = time_ns() resize!(a, 8) time_ns() - s end x = 8:10:1000000 y = f.(x) plot(x, y) ``` ![image](https://github.com/user-attachments/assets/5a1fb963-7d44-4cac-bedd-6f0733d4cf56) (cherry picked from commit e802eff)
1 parent 92405f2 commit 05182dc

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

base/genericmemory.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,16 @@ function _unsetindex!(A::MemoryRef{T}) where T
8080
MemT = typeof(mem)
8181
arrayelem = datatype_arrayelem(MemT)
8282
elsz = datatype_layoutsize(MemT)
83-
isboxed = 1; isunion = 2
83+
isbits = 0; isboxed = 1; isunion = 2
84+
arrayelem == isbits && datatype_pointerfree(T::DataType) && return A
8485
t = @_gc_preserve_begin mem
8586
p = Ptr{Ptr{Cvoid}}(@inbounds pointer(A))
8687
if arrayelem == isboxed
8788
Intrinsics.atomic_pointerset(p, C_NULL, :monotonic)
8889
elseif arrayelem != isunion
89-
if !datatype_pointerfree(T::DataType)
90-
for j = 1:Core.sizeof(Ptr{Cvoid}):elsz
91-
# XXX: this violates memory ordering, since it writes more than one C_NULL to each
92-
Intrinsics.atomic_pointerset(p + j - 1, C_NULL, :monotonic)
93-
end
90+
for j = 1:Core.sizeof(Ptr{Cvoid}):elsz
91+
# XXX: this violates memory ordering, since it writes more than one C_NULL to each
92+
Intrinsics.atomic_pointerset(p + j - 1, C_NULL, :monotonic)
9493
end
9594
end
9695
@_gc_preserve_end t

0 commit comments

Comments
 (0)