Skip to content

Commit

Permalink
Use a mutable type instead of ref fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tecosaur committed Aug 11, 2024
1 parent 04b2323 commit 37a1748
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/JuliaSyntaxHighlighting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ function paren_type(k::Kind)
end
end

struct ParenDepthCounter
paren::Base.RefValue{UInt}
bracket::Base.RefValue{UInt}
curly::Base.RefValue{UInt}
mutable struct ParenDepthCounter
paren::UInt
bracket::UInt
curly::UInt
end

ParenDepthCounter() =
ParenDepthCounter(Ref(zero(UInt)), Ref(zero(UInt)), Ref(zero(UInt)))
ParenDepthCounter(zero(UInt), zero(UInt), zero(UInt))

struct GreenLineage
node::GreenNode
Expand Down Expand Up @@ -305,17 +305,17 @@ function _hl_annotations!(highlights::Vector{Tuple{UnitRange{Int}, Pair{Symbol,
end
elseif JuliaSyntax.is_error(nkind); :julia_error
elseif ((depthchange, ptype) = paren_type(nkind)) |> last != :none
depthref = getfield(pdepths, ptype)[]
depthref = getfield(pdepths, ptype)
pdepth = if depthchange > 0
getfield(pdepths, ptype)[] += depthchange
setfield!(pdepths, ptype, depthref + depthchange)
else
depth0 = getfield(pdepths, ptype)[]
getfield(pdepths, ptype)[] += depthchange
depth0 = getfield(pdepths, ptype)
setfield!(pdepths, ptype, depthref + depthchange)
depth0
end
if pdepth <= 0 && UNMATCHED_DELIMITERS_ENABLED[]
if pdepth <= 0 && UNMATCHED_DELIMITERS_ENABLED
:julia_unpaired_parentheses
elseif !RAINBOW_DELIMITERS_ENABLED[]
elseif !RAINBOW_DELIMITERS_ENABLED
:julia_parentheses
else
displaydepth = mod1(pdepth, MAX_PAREN_HIGHLIGHT_DEPTH)
Expand Down

0 comments on commit 37a1748

Please sign in to comment.