Skip to content

Commit 557ad85

Browse files
Use more looping to avoid intermediate allocs
1 parent 75d5608 commit 557ad85

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/topologies/halfedge.jl

+9-10
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,15 @@ function adjsort(elems::AbstractVector{<:Connectivity})
232232
found = false
233233
vinds = last(adjs)
234234
for i::Int in vinds
235-
einds = findall(e -> i e, list)
236-
if !isempty(einds)
237-
# lookup all elements that share at
238-
# least two vertices (i.e. edge)
239-
for j in sort(einds, rev=true)
240-
if length(vinds list[j]) > 1
241-
found = true
242-
push!(adjs, popat!(list, j))
243-
end
244-
end
235+
not_i = (filter(!=(i), vinds)...,)
236+
for j in reverse(eachindex(list))
237+
# equivalent to `length(vinds ∩ list[j]) > 1` but more efficient (no allocs(?))
238+
any(==(i), list[j]) || continue
239+
isdisjoint(not_i, list[j]) && continue
240+
241+
# implicitly `list[j]` contains `i` and at least one other vertex
242+
found = true
243+
push!(adjs, popat!(list, j))
245244
end
246245
end
247246

0 commit comments

Comments
 (0)