Skip to content

Commit 3fb0349

Browse files
committed
add comments
1 parent f57460b commit 3fb0349

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/green_tree.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function Base.hash(node::GreenNode, h::UInt)
7676
children = node.children
7777
if children === nothing
7878
h = hash(nothing, h)
79-
else
79+
else # optimization - avoid extra allocations from `hash(::AbstractVector, ::UInt)`
8080
for child in children
8181
h = hash(child, h)
8282
end

src/syntax_tree.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Base.hash(node::TreeNode, h::UInt)
2323
children = node.children
2424
if children === nothing
2525
return hash(nothing, h)
26-
else
26+
else # optimization - avoid extra allocations from `hash(::AbstractVector, ::UInt)`
2727
for child in children
2828
h = hash(child, h)
2929
end
@@ -62,7 +62,11 @@ struct SyntaxData <: AbstractSyntaxData
6262
end
6363

6464
Base.hash(data::SyntaxData, h::UInt) =
65-
hash(data.source, hash(data.raw, hash(data.position, Core.invoke(hash, Tuple{Any,UInt}, data.val, h))))
65+
hash(data.source, hash(data.raw, hash(data.position,
66+
# Avoid dynamic dispatch:
67+
# This does not support custom `hash` implementation that may be defined for `typeof(data.val)`,
68+
# However, such custom user types should not generally appear in the AST.
69+
Core.invoke(hash, Tuple{Any,UInt}, data.val, h))))
6670
function Base.:(==)(a::SyntaxData, b::SyntaxData)
6771
a.source == b.source && a.raw == b.raw && a.position == b.position && a.val === b.val
6872
end

0 commit comments

Comments
 (0)