Skip to content

Commit

Permalink
Improve inference of tag iteration
Browse files Browse the repository at this point in the history
Inference loses track of `Tag` due to
JuliaLang/julia#36454
  • Loading branch information
timholy committed Feb 25, 2021
1 parent 5f7e640 commit b082900
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ifds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ IFD(o::Type{O}) where {O <: Unsigned} = IFD{O}(OrderedDict{UInt16, Tag}())

Base.length(ifd::IFD) = length(ifd.tags)
Base.keys(ifd::IFD) = keys(ifd.tags)
Base.iterate(ifd::IFD) = iterate(ifd.tags)
Base.iterate(ifd::IFD, n::Integer) = iterate(ifd.tags, n)
Base.iterate(ifd::IFD) = iterate(ifd.tags)::Union{Nothing,Tuple{Pair{UInt16,<:Tag},Int}}
Base.iterate(ifd::IFD, n::Int) = iterate(ifd.tags, n)::Union{Nothing,Tuple{Pair{UInt16,<:Tag},Int}}
Base.getindex(ifd::IFD, key::TiffTag) = getindex(ifd, UInt16(key))
Base.getindex(ifd::IFD{O}, key::UInt16) where {O} = getindex(ifd.tags, key)
Base.in(key::TiffTag, v::IFD) = in(UInt16(key), v)
Expand Down Expand Up @@ -222,6 +222,7 @@ function Base.write(tf::TiffFile{O}, ifd::IFD{O}) where {O <: Unsigned}
write(tf, O(0))

for (tag, poses) in remotedata
tag = tag::Tag
data_pos = position(tf.io)
# add NUL terminator to the end of Strings that don't have it already
data = (eltype(tag) == String && !endswith(tag.data, '\0')) ? tag.data * "\0" : tag.data
Expand All @@ -230,6 +231,7 @@ function Base.write(tf::TiffFile{O}, ifd::IFD{O}) where {O <: Unsigned}
end

for (tag, poses) in remotedata
tag = tag::Tag
orig_pos, data_pos = poses
seek(tf, orig_pos)
write(tf, tag, data_pos)
Expand Down

0 comments on commit b082900

Please sign in to comment.