Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Commit 2103a21

Browse files
authored
Don't allocate new memory in convert when element type is unchanged (#279)
Fixes #278
1 parent 78327d1 commit 2103a21

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/dataarray.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,12 @@ function Base.convert{S, T, N}(::Type{DataArray{S, N}},
274274
a::AbstractArray{T, N}) # -> DataArray{S, N}
275275
return DataArray(convert(Array{S, N}, a), falses(size(a)))
276276
end
277-
Base.convert{S,T,N}(::Type{DataArray{S}}, x::AbstractArray{T,N}) =
278-
convert(DataArray{S,N}, x)
277+
Base.convert{S, T, N}(::Type{DataArray{S}}, x::AbstractArray{T, N}) =
278+
convert(DataArray{S, N}, x)
279279
Base.convert{T, N}(::Type{DataArray}, x::AbstractArray{T, N}) =
280-
convert(DataArray{T,N}, x)
281-
282-
function Base.convert{S, T, N}(::Type{DataArray{S, N}},
283-
x::DataArray{T, N}) # -> DataArray{S, N}
280+
convert(DataArray{T, N}, x)
281+
Base.convert{T, N}(::Type{DataArray{T, N}}, x::DataArray{T, N}) = x
282+
function Base.convert{S, T, N}(::Type{DataArray{S, N}}, x::DataArray{T, N}) # -> DataArray{S, N}
284283
v = similar(x.data, S)
285284
@inbounds for i = 1:length(x)
286285
if !x.na[i]

test/dataarray.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,9 @@
100100

101101
# Inferrability of map (#276)
102102
@test eltype(map(x -> x > 1, @data [1, 2])) == Bool
103+
104+
@testset "Issue #278" begin
105+
x = @data ones(4)
106+
@test parent(view(x, :)).data === x.data
107+
end
103108
end

0 commit comments

Comments
 (0)