Skip to content

Commit 5a45f73

Browse files
authored
Merge pull request #50 from jaakkor2/patch-1
Reduce invalidations by defining isless and ==
2 parents 7c49836 + f6cd5f2 commit 5a45f73

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/ProgressLogging.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ end
193193
# previous `progress` key based specification, we create a custom
194194
# string type that has `Progress` attached to it. This is used as the
195195
# third argument `message` of `Logging.handle_message`.
196-
struct ProgressString <: AbstractString
196+
struct ProgressString
197197
progress::Progress
198198
end
199199

@@ -208,13 +208,14 @@ Base.string(str::ProgressString) = str.progress.name
208208

209209
Base.print(io::IO, str::ProgressString) = print(io, string(str))
210210
Base.convert(::Type{ProgressString}, str::ProgressString) = str
211-
Base.convert(::Type{T}, str::ProgressString) where {T<:AbstractString} =
212-
convert(T, str.progress.name)
213211

214-
# Define `cmp` to make `==` etc. work
215-
Base.cmp(a::AbstractString, b::ProgressString) = cmp(a, string(b))
216-
Base.cmp(a::ProgressString, b::AbstractString) = cmp(string(a), b)
217-
Base.cmp(a::ProgressString, b::ProgressString) = cmp(string(a), string(b))
212+
# Define `isless` and `==` to make comparisons work
213+
Base.isless(a::AbstractString, b::ProgressString) = isless(a, string(b))
214+
Base.isless(a::ProgressString, b::AbstractString) = isless(string(a), b)
215+
Base.isless(a::ProgressString, b::ProgressString) = isless(string(a), string(b))
216+
Base.:(==)(a::AbstractString, b::ProgressString) = a == string(b)
217+
Base.:(==)(a::ProgressString, b::AbstractString) = string(a) == b
218+
Base.:(==)(a::ProgressString, b::ProgressString) = string(a) == string(b)
218219

219220
# Avoid using `show(::IO, ::AbstractString)` which expects
220221
# `Base.print_quoted` to work.

0 commit comments

Comments
 (0)