Skip to content

Commit be71982

Browse files
committed
Do not coerce attrs to NamedTuple unnecessarily
For `ensure_attributes` and `delete_attributes`, the output graph's `.attributes` now have the same type (`Dict` or `NamedTuple`) as the input. Add `delete_attributes!` defined only on dict-attrs to be consistent with `ensure_attributes!`
1 parent 26b81e2 commit be71982

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/syntax_graph.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,31 @@ function ensure_attributes!(graph::SyntaxGraph{<:Dict}; kws...)
6060
end
6161
graph
6262
end
63+
function ensure_attributes(graph::SyntaxGraph{<:Dict}; kws...)
64+
g = unfreeze_attrs(graph)
65+
ensure_attributes!(g; kws...)
66+
end
6367

64-
function ensure_attributes(graph::SyntaxGraph; kws...)
68+
function ensure_attributes(graph::SyntaxGraph{<:NamedTuple}; kws...)
6569
g = unfreeze_attrs(graph)
6670
ensure_attributes!(g; kws...)
6771
freeze_attrs(g)
6872
end
6973

70-
function delete_attributes(graph::SyntaxGraph, attr_names...)
71-
attributes = Dict(pairs(graph.attributes)...)
74+
function delete_attributes!(graph::SyntaxGraph{<:Dict}, attr_names::Symbol...)
7275
for name in attr_names
73-
delete!(attributes, name)
76+
delete!(graph.attributes, name)
7477
end
75-
SyntaxGraph(graph.edge_ranges, graph.edges, (; pairs(attributes)...))
78+
graph
79+
end
80+
81+
function delete_attributes(graph::SyntaxGraph{<:Dict}, attr_names::Symbol...)
82+
delete_attributes!(unfreeze_attrs(graph), attr_names...)
83+
end
84+
85+
function delete_attributes(graph::SyntaxGraph{<:NamedTuple}, attr_names::Symbol...)
86+
g = delete_attributes!(unfreeze_attrs(graph), attr_names...)
87+
freeze_attrs(g)
7688
end
7789

7890
function newnode!(graph::SyntaxGraph)

0 commit comments

Comments
 (0)