Skip to content

Commit adff9bc

Browse files
committed
Cache operator string in printout
1 parent 8385da4 commit adff9bc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Equation.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,19 @@ const OP_NAMES = Dict(
190190
"safe_pow" => "^",
191191
)
192192

193-
function get_op_name(op::String)
194-
return get(OP_NAMES, op, op)
193+
@generated function get_op_name(op::F) where {F}
194+
try
195+
# Bit faster to just cache the name of the operator:
196+
op_s = string(F.instance)
197+
out = get(OP_NAMES, op_s, op_s)
198+
return :($out)
199+
catch
200+
end
201+
return quote
202+
op_s = string(op)
203+
out = get(OP_NAMES, op_s, op_s)
204+
return out
205+
end
195206
end
196207

197208
function string_op(

0 commit comments

Comments
 (0)