Skip to content

Commit

Permalink
More efficient eager Array conversion for OffsetArray (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 authored Oct 22, 2021
1 parent 43fab62 commit 324e8a4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/showmime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@ csnormalize(c::Colorant) = RGBA(c)

# Unless we have PNG IO backend that works on generic array types, we have to eagerly
# convert it to dense array types
# On performance: if the array type(e.g., OffsetArray) has efficient convert method to Array
# then this is almost a no-op
enforce_standard_dense_array(A::AbstractArray) = convert(Array, A)
# On performance: if the array type has efficient convert method to Array then this is
# almost a no-op
function enforce_standard_dense_array(A::AbstractArray)
if Base.has_offset_axes(A)
convert(Array, OffsetArrays.no_offset_view(A))
else
convert(Array, A)
end
end
enforce_standard_dense_array(A::DenseArray) = A
enforce_standard_dense_array(A::OffsetArray) = enforce_standard_dense_array(parent(A))
# TODO(johnnychen94): Uncomment this when we set direct dependency to PNGFiles.
# enforce_standard_dense_array(A::IndirectArray) = A # PNGFiles has built-in support for IndirectArray.

const ColorantMatrix{T<:Colorant} = AbstractMatrix{T}

Expand Down

2 comments on commit 324e8a4

@johnnychen94
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/47271

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.3 -m "<description of version>" 324e8a4c39ade79ef689e6bf97b1f2ea54682050
git push origin v0.3.3

Please sign in to comment.