Skip to content

Commit 0c3431d

Browse files
option for copying
1 parent 736f770 commit 0c3431d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/RecursiveArrayTools.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ module RecursiveArrayTools
4141
f(v)
4242
end
4343

44-
@inline function copyat_or_push!{T}(a::AbstractVector{T},i::Int,x)
44+
@inline function copyat_or_push!{T,perform_copy}(a::AbstractVector{T},i::Int,x,nc::Type{Val{perform_copy}}=Val{true})
4545
@inbounds if length(a) >= i
46-
if T <: Number
46+
if T <: Number || !perform_copy
4747
a[i] = x
4848
else
4949
recursivecopy!(a[i],x)
@@ -53,9 +53,17 @@ module RecursiveArrayTools
5353
# Have to check that it's <: Array or can have problems
5454
# with abstract arrays like MultiScaleModels.
5555
# Have to check <: Number since it could just be a number...
56-
push!(a,copy(x))
56+
if perform_copy
57+
push!(a,copy(x))
58+
else
59+
push!(a,x)
60+
end
5761
else
58-
push!(a,deepcopy(x))
62+
if perform_copy
63+
push!(a,deepcopy(x))
64+
else
65+
push!(a,x)
66+
end
5967
end
6068
end
6169
nothing

0 commit comments

Comments
 (0)