diff --git a/README.md b/README.md index 1f099c77a..e7376c776 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `bswap` is supported for `Complex` arguments on 0.5 and below. ([#21346]) +* `Compat.StringVector` is supported on 0.5 and below. On 0.6 and later, it aliases `Base.StringVector`. This function allocates a `Vector{UInt8}` whose data can be made into a `String` in constant time; that is, without copying. On 0.5 and later, use `String(...)` with the vector allocated by `StringVector` as an argument to create a string without copying. Note that if 0.4 support is needed, `Compat.UTF8String(...)` should be used instead. ([#19449]) + ## Renamed functions * `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively diff --git a/src/Compat.jl b/src/Compat.jl index cd7a49b5e..d672e46fd 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1464,6 +1464,13 @@ if VERSION < v"0.6.0-pre.beta.102" Base.bswap(z::Complex) = Complex(bswap(real(z)), bswap(imag(z))) end +# https://github.com/JuliaLang/julia/pull/19449 +if VERSION < v"0.6.0-dev.1988" + StringVector(n::Integer) = Vector{UInt8}(n) +else + using Base: StringVector +end + include("to-be-deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 06ad23148..8b815e570 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1822,6 +1822,15 @@ let zbuf = IOBuffer([0xbf, 0xc0, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00, @test bswap(z2) === 3.5 - 4.5im end +# PR 19449 +using Compat: StringVector +@test length(StringVector(5)) == 5 +@test String(fill!(StringVector(5), 0x61)) == "aaaaa" + +let x = fill!(StringVector(5), 0x61) + @test pointer(x) == pointer(Compat.UTF8String(x)) +end + include("to-be-deprecated.jl") nothing