Skip to content

Commit 9c2f87e

Browse files
author
Pietro Vertechi
authored
Clean up code in the require block (#44)
* remove dispatch for string array * use trait for permutable * use fastpermute directly * dispatch
1 parent 63340e1 commit 9c2f87e

File tree

4 files changed

+7
-25
lines changed

4 files changed

+7
-25
lines changed

src/StructArrays.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ include("lazy.jl")
1414
function __init__()
1515
Requires.@require Tables="bd369af6-aec1-5ad0-b16a-f7cc5008161c" include("tables.jl")
1616
Requires.@require PooledArrays="2dfb63ee-cc39-5dd5-95bd-886bf059d720" begin
17-
ispooledarray(::PooledArrays.PooledArray) = true
17+
fastpermute!(v::PooledArrays.PooledArray, p::AbstractVector) = permute!(v, p)
1818
end
1919
Requires.@require WeakRefStrings="ea10d353-3f73-51f8-a26c-33c1cb351aa5" begin
20-
isstringarray(::WeakRefStrings.StringArray) = true
21-
default_array(::Type{T}, d) where {T<:Union{AbstractString, Missing}} = WeakRefStrings.StringArray{T}(d)
20+
fastpermute!(v::WeakRefStrings.StringArray, p::AbstractVector) = permute!(v, p)
2221
end
2322
end
2423

src/collect.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
default_array(::Type{S}, d) where {S} = Array{S}(undef, d)
2-
default_array(::Type{Missing}, d) = Array{Missing}(undef, d)
32

43
struct StructArrayInitializer{F, G}
54
unwrap::F

src/sort.jl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
using Base.Sort, Base.Order
22

3-
isstringarray(::AbstractArray) = false
4-
ispooledarray(::AbstractArray) = false
5-
6-
function Base.permute!(c::StructVector, p::AbstractVector)
7-
foreachfield(c) do v
8-
if v isa StructVector || isstringarray(v) || ispooledarray(v)
9-
permute!(v, p)
10-
else
11-
copyto!(v, v[p])
12-
end
13-
end
3+
fastpermute!(v::AbstractArray, p::AbstractVector) = copyto!(v, v[p])
4+
fastpermute!(v::StructArray, p::AbstractVector) = permute!(v, p)
5+
6+
function Base.permute!(c::StructArray, p::AbstractVector)
7+
foreachfield(v -> fastpermute!(v, p), c)
148
return c
159
end
1610

test/runtests.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ end
2323
a = WeakRefStrings.StringVector(["a", "b", "c"])
2424
b = PooledArrays.PooledArray([1, 2, 3])
2525
c = [:a, :b, :c]
26-
@test !StructArrays.ispooledarray(a)
27-
@test StructArrays.isstringarray(a)
28-
@test StructArrays.ispooledarray(b)
29-
@test !StructArrays.isstringarray(b)
30-
@test !StructArrays.ispooledarray(c)
31-
@test !StructArrays.isstringarray(c)
3226
s = StructArray(a=a, b=b, c=c)
3327
permute!(s, [2, 3, 1])
3428
@test s.a == ["b", "c", "a"]
@@ -247,10 +241,6 @@ StructArrays.SkipConstructor(::Type{<:S}) = true
247241
end
248242

249243
@testset "default_array" begin
250-
v = StructArrays.default_array(String, (2, 3))
251-
@test v isa WeakRefStrings.StringArray{String, 2}
252-
v = StructArrays.default_array(Union{String, Missing}, (2, 3))
253-
@test v isa WeakRefStrings.StringArray{Union{String, Missing}, 2}
254244
v = StructArrays.default_array(Missing, (2,))
255245
@test v isa Array{Missing, 1}
256246
v = StructArrays.default_array(Int, (2,))

0 commit comments

Comments
 (0)