You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An Array is often still allocated on output, but this gives the compiler
a chance to potentially elide that in certain cases.
For measurement, it seems about 10% faster as a string builder:
julia> @Btime repr("hello\nworld"^10);
1.096 μs (10 allocations: 640 bytes) # master
973.000 ns (9 allocations: 608 bytes) # PR
994.000 ns (8 allocations: 576 bytes) # also PR, after Revise-ing Base.wrap
"Attempted to wrap a MemoryRef of length $len with an Array of size dims=$dims, which is invalid because prod(dims) = $proddims > $len, so that the array would have more elements than the underlying memory can store."))
3084
3085
3085
-
functionwrap(::Type{Array}, m::Memory{T}, dims::NTuple{N, Integer}) where {T, N}
3086
-
wrap(Array, MemoryRef(m), dims)
3086
+
@eval@propagate_inboundsfunctionwrap(::Type{Array}, m::MemoryRef{T}, dims::NTuple{N, Integer}) where {T, N}
3087
+
dims =convert(Dims, dims)
3088
+
ref =_wrap(m, dims)
3089
+
$(Expr(:new, :(Array{T, N}), :ref, :dims))
3090
+
end
3091
+
3092
+
@eval@propagate_inboundsfunctionwrap(::Type{Array}, m::Memory{T}, dims::NTuple{N, Integer}) where {T, N}
3093
+
dims =convert(Dims, dims)
3094
+
ref =_wrap(MemoryRef(m), dims)
3095
+
$(Expr(:new, :(Array{T, N}), :ref, :dims))
3096
+
end
3097
+
@eval@propagate_inboundsfunctionwrap(::Type{Array}, m::MemoryRef{T}, l::Integer) where {T}
3098
+
dims = (Int(l),)
3099
+
ref =_wrap(m, dims)
3100
+
$(Expr(:new, :(Array{T, 1}), :ref, :dims))
3087
3101
end
3088
-
functionwrap(::Type{Array}, m::MemoryRef{T}, l::Integer) where {T}
3089
-
wrap(Array, m, (l,))
3102
+
@eval@propagate_inboundsfunctionwrap(::Type{Array}, m::Memory{T}, l::Integer) where {T}
3103
+
dims = (Int(l),)
3104
+
ref =_wrap(MemoryRef(m), (l,))
3105
+
$(Expr(:new, :(Array{T, 1}), :ref, :dims))
3090
3106
end
3091
-
functionwrap(::Type{Array}, m::Memory{T}, l::Integer) where {T}
3092
-
wrap(Array, MemoryRef(m), (l,))
3107
+
@eval@propagate_inboundsfunctionwrap(::Type{Array}, m::Memory{T}) where {T}
0 commit comments