Skip to content

Commit 6007ffa

Browse files
committed
Fix issue pointed out by jakobnissen
1 parent a76df84 commit 6007ffa

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

base/strings/string.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,12 @@ end
8080
function String(v::ReinterpretArray{UInt8, 1, S, Vector{S}, IsReshaped}) where {S, IsReshaped}
8181
len = length(v)
8282
len == 0 && return ""
83-
ref = v.parent.ref
84-
if ref.ptr_or_offset == ref.mem.ptr
85-
str = ccall(:jl_genericmemory_to_string, Ref{String}, (Any, Int), ref.mem, len)
86-
else
87-
str = ccall(:jl_pchar_to_string, Ref{String}, (Ptr{S}, Int), ref, len)
88-
end
89-
# optimized empty!(v.parent); sizehint!(v.parent, 0) calls
90-
setfield!(v.parent, :size, (0,))
91-
setfield!(v.parent, :ref, memoryref(Memory{S}()))
92-
return str
83+
return ccall(:jl_pchar_to_string, Ref{String}, (Ptr{S}, Int), v.parent.ref, len)
84+
end
85+
function String(v::ReinterpretArray{UInt8, 1, S, Memory{S}, IsReshaped}) where {S, IsReshaped}
86+
len = length(v)
87+
len == 0 && return ""
88+
return ccall(:jl_pchar_to_string, Ref{String}, (Ptr{S}, Int), v.parent.ptr, len)
9389
end
9490

9591
"Create a string re-using the memory, if possible.

0 commit comments

Comments
 (0)