From a7c9249142c6442bd90382cc423fa98029a491cd Mon Sep 17 00:00:00 2001 From: leburgel Date: Tue, 20 Oct 2026 20:27:14 +0200 Subject: [PATCH] Return early from `isless` for equal product sectors Co-Authored-By: Claude Opus 5.5 --- src/product.jl | 2 ++ test/sectors.jl | 1 + 2 files changed, 3 insertions(+) diff --git a/src/product.jl b/src/product.jl index bafca661..a88f275b 100644 --- a/src/product.jl +++ b/src/product.jl @@ -229,6 +229,8 @@ hopflink(p::I, q::I) where {I <: ProductSector} = *(hopflink.(p.sectors, q.secto Base.isequal(p1::ProductSector, p2::ProductSector) = isequal(p1.sectors, p2.sectors) Base.hash(p::ProductSector, h::UInt) = hash(p.sectors, h) function Base.isless(a::I, b::I) where {I <: ProductSector} + # cheap, and common when comparing tuples of sectors (equal entries until the first difference) + isequal(a, b) && return false I1 = findindex.(values.(_sectors(I)), a.sectors) I2 = findindex.(values.(_sectors(I)), b.sectors) d1 = sum(I1) - length(I1) diff --git a/test/sectors.jl b/test/sectors.jl index 6c6d1c3d..55f462d8 100644 --- a/test/sectors.jl +++ b/test/sectors.jl @@ -76,6 +76,7 @@ end for s in rest i += 1 @test !isless(s, sprev) + @test !isless(s, s) @test s == @testinferred(values(I)[i]) @test findindex(values(I), s) == i sprev = s