Skip to content

Commit 0f09e28

Browse files
committed
Fix perf and add compat for :position access
1 parent dab8423 commit 0f09e28

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/syntax_tree.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ struct SyntaxData <: AbstractSyntaxData
6060
byte_end::UInt32
6161
val::Any
6262
end
63+
function Base.getproperty(data::SyntaxData, name::Symbol)
64+
if name === :position
65+
# Previous versions of JuliaSyntax had `position::Int`.
66+
# Allow access for compatibility. It was renamed (with changed) semantics
67+
# to `byte_end::UInt32` to match the rest of the code base, which identified
68+
# nodes, by their last byte.
69+
return Int(getfield(data, :byte_end) - getfield(data, :raw).node_span + UInt32(1))
70+
end
71+
return getfield(data, name)
72+
end
6373

6474
Base.hash(data::SyntaxData, h::UInt) =
6575
hash(data.source, hash(data.raw, hash(data.byte_end,

src/tree_cursors.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,16 @@ function Base.iterate(cursor::TopLevelSiblingIterator{C}, last::C) where {C}
143143
this === nothing && return nothing
144144
return (this, this)
145145
end
146+
147+
# HACK: Force inlining of `filter` for our cursors to avoid significant perf
148+
# degradation.
149+
@inline function Base.iterate(f::Iterators.Filter{<:Any, Iterators.Reverse{T}}, state...) where {T<:Union{RedTreeCursor, GreenTreeCursor}}
150+
y = iterate(f.itr, state...)
151+
while y !== nothing
152+
if f.flt(y[1])
153+
return y
154+
end
155+
y = iterate(f.itr, y[2])
156+
end
157+
nothing
158+
end

0 commit comments

Comments
 (0)