Skip to content

Commit 32bc1ae

Browse files
committed
Avoid intermediate allocation for == with mismatching types
1 parent de7fee7 commit 32bc1ae

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/tree_map.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ function any(f::F, tree::Node) where {F<:Function}
121121
end
122122
end
123123

124-
function Base.:(==)(a::Node{T}, b::Node{T})::Bool where {T}
124+
function Base.:(==)(a::Node{T1}, b::Node{T2})::Bool where {T1,T2}
125125
(degree = a.degree) != b.degree && return false
126126
if degree == 0
127127
(constant = a.constant) != b.constant && return false
128128
if constant
129-
return a.val::T == b.val::T
129+
return a.val::T1 == b.val::T2
130130
else
131131
return a.feature == b.feature
132132
end
@@ -136,11 +136,6 @@ function Base.:(==)(a::Node{T}, b::Node{T})::Bool where {T}
136136
return a.op == b.op && a.l == b.l && a.r == b.r
137137
end
138138
end
139-
function Base.:(==)(a::Node{T1}, b::Node{T2})::Bool where {T1,T2}
140-
# TODO: Should also have preserve_sharing check... But how?
141-
T = promote_type(T1, T2)
142-
return Node{T}(a) == Node{T}(b)
143-
end
144139

145140
###############################################################################
146141
# Derived functions: ##########################################################

0 commit comments

Comments
 (0)