From 0656b805d65ed1d333ed9fd9e946beec0b5ca094 Mon Sep 17 00:00:00 2001 From: Jaakko Ruohio Date: Mon, 15 Sep 2025 08:36:49 +0300 Subject: [PATCH 1/2] Reduce invalidations by defining isless and == --- src/ProgressLogging.jl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ProgressLogging.jl b/src/ProgressLogging.jl index 30dd87a..4d8dff9 100644 --- a/src/ProgressLogging.jl +++ b/src/ProgressLogging.jl @@ -193,7 +193,7 @@ end # previous `progress` key based specification, we create a custom # string type that has `Progress` attached to it. This is used as the # third argument `message` of `Logging.handle_message`. -struct ProgressString <: AbstractString +struct ProgressString progress::Progress end @@ -211,10 +211,13 @@ Base.convert(::Type{ProgressString}, str::ProgressString) = str Base.convert(::Type{T}, str::ProgressString) where {T<:AbstractString} = convert(T, str.progress.name) -# Define `cmp` to make `==` etc. work -Base.cmp(a::AbstractString, b::ProgressString) = cmp(a, string(b)) -Base.cmp(a::ProgressString, b::AbstractString) = cmp(string(a), b) -Base.cmp(a::ProgressString, b::ProgressString) = cmp(string(a), string(b)) +# Define `isless` and `==` to make comparisons work +Base.isless(a::AbstractString, b::ProgressString) = isless(a, string(b)) +Base.isless(a::ProgressString, b::AbstractString) = isless(string(a), b) +Base.isless(a::ProgressString, b::ProgressString) = isless(string(a), string(b)) +Base.:(==)(a::AbstractString, b::ProgressString) = a == string(b) +Base.:(==)(a::ProgressString, b::AbstractString) = string(a) == b +Base.:(==)(a::ProgressString, b::ProgressString) = string(a) == string(b) # Avoid using `show(::IO, ::AbstractString)` which expects # `Base.print_quoted` to work. From f6cd5f220a0197d734779f18941c36a3a5c95e36 Mon Sep 17 00:00:00 2001 From: Jaakko Ruohio Date: Sun, 28 Sep 2025 07:38:39 +0300 Subject: [PATCH 2/2] Remove invalidating Base.convert definition --- src/ProgressLogging.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ProgressLogging.jl b/src/ProgressLogging.jl index 4d8dff9..6a26062 100644 --- a/src/ProgressLogging.jl +++ b/src/ProgressLogging.jl @@ -208,8 +208,6 @@ Base.string(str::ProgressString) = str.progress.name Base.print(io::IO, str::ProgressString) = print(io, string(str)) Base.convert(::Type{ProgressString}, str::ProgressString) = str -Base.convert(::Type{T}, str::ProgressString) where {T<:AbstractString} = - convert(T, str.progress.name) # Define `isless` and `==` to make comparisons work Base.isless(a::AbstractString, b::ProgressString) = isless(a, string(b))