Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JuliaLang/Compat.jl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5b7b3ae97b91c96014e473e9cdb12b2ff649b71e
Choose a base ref
..
head repository: JuliaLang/Compat.jl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cef63c1159a65b339c764682c3452cd322ab3080
Choose a head ref
Showing with 23 additions and 3 deletions.
  1. +2 −0 README.md
  2. +9 −2 src/Compat.jl
  3. +12 −1 test/runtests.jl
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -165,6 +165,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
11 changes: 9 additions & 2 deletions src/Compat.jl
Original file line number Diff line number Diff line change
@@ -1464,14 +1464,21 @@ 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

# https://github.com/JuliaLang/julia/pull/21257
if v"0.5.0" <= VERSION < v"0.6.0-pre.beta.28"
collect(A) = collect_indices(indices(A), A)
collect_indices(::Tuple{}, A) = copy!(Array{eltype(A)}(), A)
collect_indices(indsA::Tuple{Vararg{Base.OneTo}}, A) =
copy!(Array{eltype(A)}(length.(indsA)), A)
copy!(Array{eltype(A)}(map(length, indsA)), A)
function collect_indices(indsA, A)
B = Array{eltype(A)}(length.(indsA))
B = Array{eltype(A)}(map(length, indsA))
copy!(B, CartesianRange(indices(B)), A, CartesianRange(indsA))
end
else
13 changes: 12 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1822,11 +1822,22 @@ 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

# collect
if VERSION >= v"0.5.0"
using OffsetArrays
a = OffsetArray(1:3, -1:1)
@test Compat.collect(a) == [1,2,3]
b = Compat.collect(a)
@test indices(b) === (Base.OneTo(3),)
@test b == [1,2,3]
end

include("to-be-deprecated.jl")