julia
95fb1c59 - make reverse(::StringView) return String (#61579)

Commit
40 days ago
make reverse(::StringView) return String (#61579) As commented https://github.com/JuliaLang/julia/pull/60526#discussion_r3074716617, I think `reverse(::StringView)` should return `String` instead of `StringView{Memory{UInt8}}`. It can't generally return the same type of `StringView` anyway (because the original `data` array type might not be mutable), it has to make a copy anyway, and so my feeling is that we might as well return `String`. This allows the implementation to be merged with the nearly identical implementation for `String`. Returning `String` also has the advantage that the result can be passed to a `ccall` expecting NUL termination without making a copy. As discussed in https://github.com/JuliaLang/julia/issues/6165#issuecomment-124128940: > we need a reverse function for only one reason: efficient reversed-order string processing with external libraries, especially PCRE. so the main reason for `reverse` on a string is, in fact, passing to `ccall`. (This is not breaking because the `StringView` feature has not yet been released. Also note that the StringViews.jl package has returned `String` from `reverse` for some time now and no one has complained.)
Author
Parents
Loading