diff --git a/src/Runic.jl b/src/Runic.jl index 2031191..f73c52b 100644 --- a/src/Runic.jl +++ b/src/Runic.jl @@ -146,6 +146,7 @@ mutable struct Context next_sibling::Union{Node, Nothing} # parent::Union{Node, Nothing} lineage_kinds::Vector{JuliaSyntax.Kind} + tmp_buf::IOBuffer end function Context( @@ -178,6 +179,7 @@ function Context( return Context( src_str, src_tree, src_io, fmt_io, fmt_tree, quiet, verbose, assert, debug, check, diff, filemode, call_depth, indent_level, prev_sibling, next_sibling, lineage_kinds, + IOBuffer(), ) end diff --git a/src/chisels.jl b/src/chisels.jl index 9337ccb..febb243 100644 --- a/src/chisels.jl +++ b/src/chisels.jl @@ -557,6 +557,8 @@ end # Utilities for IOBuffer # ########################## +const backup_buffer = IOBuffer() + # Replace bytes for a node at the current position in the IOBuffer. `size` is the current # window for the node, i.e. the number of bytes until the next node starts. If `size` is # smaller or larger than the length of `bytes` this method will shift the bytes for @@ -568,7 +570,8 @@ function replace_bytes!(io::IOBuffer, bytes::Union{String, AbstractVector{UInt8} nw = write(io, bytes) @assert nb == nw else - backup = IOBuffer() # TODO: global const (with lock)? + # backup = IOBuffer() # TODO: global const (with lock)? + backup = truncate(backup_buffer, 0) seek(io, pos + size) @assert position(io) == pos + size nb_written_to_backup = write(backup, io)