diff --git a/Project.toml b/Project.toml index 17f558c..8db9c7a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ITensorBase" uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7" -version = "0.12.3" +version = "0.12.4" authors = ["ITensor developers and contributors"] [workspace] diff --git a/src/index.jl b/src/index.jl index af11093..cc59e8c 100644 --- a/src/index.jl +++ b/src/index.jl @@ -85,14 +85,18 @@ Return the prime level of an index or index name: a non-negative integer raised """ plev(n::IndexName) = getfield(n, :plev) +# The tags dictionary is the only costly field to compare, so short-circuit it with `===`: +# a name reused across tensors carries the same tags object and skips the dictionary walk. function Base.:(==)(n1::IndexName, n2::IndexName) return uuid(n1) == uuid(n2) && plev(n1) == plev(n2) && - tags_stored(n1) == tags_stored(n2) + (tags_stored(n1) === tags_stored(n2) || tags_stored(n1) == tags_stored(n2)) end function Base.isequal(n1::IndexName, n2::IndexName) - return isequal(uuid(n1), uuid(n2)) && - isequal(plev(n1), plev(n2)) && - isequal(tags_stored(n1), tags_stored(n2)) + return isequal(uuid(n1), uuid(n2)) && isequal(plev(n1), plev(n2)) && + ( + tags_stored(n1) === tags_stored(n2) || + isequal(tags_stored(n1), tags_stored(n2)) + ) end function Base.isless(n1::IndexName, n2::IndexName) t1 = (uuid(n1), plev(n1), keys(tags_stored(n1)), values(tags_stored(n1)))