Skip to content

Commit

Permalink
Fix string from vector
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobnissen committed May 10, 2024
1 parent 5326d0d commit 46bba01
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion base/strings/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ function String(v::Vector{UInt8})
# This method copies the content of the Memory such that the underlying
# Memory is unchanged, but then empties the Vector and re-assigns a new
# empty memory to the string.
str = String(StringMemory(len))
mem = StringMemory(len)
GC.@preserve mem v unsafe_copyto!(pointer(mem), pointer(v), len)
str = takestring!(mem)
# optimized empty!(v); sizehint!(v, 0) calls
setfield!(v, :size, (0,))
setfield!(v, :ref, MemoryRef(Memory{UInt8}()))
Expand Down

0 comments on commit 46bba01

Please sign in to comment.