Skip to content

Commit 3b5d1d3

Browse files
author
Pietro Vertechi
authored
avoid unnecessary generated function (#120)
* remove generated in roweq * avoid unnecessary Base * remove generated function on rowcmp
1 parent ab45e83 commit 3b5d1d3

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/groupjoin.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# Important, for broadcast joins we cannot assume c and d have same number of columns:
22
# c could have more columns than d
3-
@generated function rowcmp(c::StructVector, i, d::StructVector{C, D}, j) where {C, D}
4-
N = fieldcount(D)
5-
ex = :(cmp(getfield(fieldarrays(c),$N)[i], getfield(fieldarrays(d),$N)[j]))
6-
for n in N-1:-1:1
7-
ex = quote
8-
let k = rowcmp(getfield(fieldarrays(c),$n), i, getfield(fieldarrays(d),$n), j)
9-
(k == 0) ? ($ex) : k
10-
end
11-
end
3+
rowcmp(::Tuple, i, ::Tuple{}, j) = 0
4+
5+
function rowcmp(tc::Tuple, i, td::Tuple, j)
6+
c, d = tc[1], td[1]
7+
let k = rowcmp(c, i, d, j)
8+
(k == 0) ? rowcmp(tail(tc), i, tail(td), j) : k
129
end
13-
ex
10+
end
11+
12+
function rowcmp(c::StructVector, i, d::StructVector, j)
13+
tc = Tuple(fieldarrays(c))
14+
td = Tuple(fieldarrays(d))
15+
return rowcmp(tc, i, td, j)
1416
end
1517

1618
@inline function rowcmp(c::AbstractVector, i, d::AbstractVector, j)

src/sort.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,9 @@ Base.eltype(::Type{<:GroupPerm}) = UnitRange{Int}
3838
return eq
3939
end
4040

41-
@generated function roweq(c::StructVector{D,C}, i, j) where {D,C}
42-
N = fieldcount(C)
43-
ex = :(roweq(getfield(fieldarrays(c),1), i, j))
44-
for n in 2:N
45-
ex = :(($ex) && (roweq(getfield(fieldarrays(c),$n), i, j)))
46-
end
47-
ex
48-
end
41+
roweq(t::Tuple{}, i, j) = true
42+
roweq(t::Tuple, i, j) = roweq(t[1], i, j) ? roweq(tail(t), i, j) : false
43+
roweq(s::StructArray, i, j) = roweq(Tuple(fieldarrays(s)), i, j)
4944

5045
function uniquesorted(keys, perm=sortperm(keys))
5146
(keys[perm[idxs[1]]] for idxs in GroupPerm(keys, perm))

0 commit comments

Comments
 (0)