Skip to content

Commit 208309c

Browse files
refactor: use WeakCacheSet for hashconsing
1 parent bfafdf5 commit 208309c

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/types.jl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function exprtype(x::BasicSymbolic)
8888
end
8989
end
9090

91-
const wvd = TaskLocalValue{WeakValueDict{UInt, BasicSymbolic}}(WeakValueDict{UInt, BasicSymbolic})
91+
const wcs = TaskLocalValue{WeakCacheSet{BasicSymbolic}}(WeakCacheSet{BasicSymbolic})
9292

9393
# Same but different error messages
9494
@noinline error_on_type() = error("Internal error: unreachable reached!")
@@ -547,20 +547,12 @@ function BasicSymbolic(s::BasicSymbolic)::BasicSymbolic
547547
if !ENABLE_HASHCONSING[]
548548
return s
549549
end
550-
cache = wvd[]
551-
h = hash2(s)
552-
k = get!(cache, h, s)
553-
if isequal_with_metadata(k, s)
554-
if iszero(k.id[])
555-
k.id[] = @atomic ID_COUNTER.x += 1
556-
end
557-
return k
558-
else
559-
if iszero(s.id[])
560-
s.id[] = @atomic ID_COUNTER.x += 1
561-
end
562-
return s
550+
cache = wcs[]
551+
k = getkey!(cache, s)
552+
if iszero(k.id[])
553+
k.id[] = @atomic ID_COUNTER.x += 1
563554
end
555+
return k
564556
end
565557

566558
function Sym{T}(name::Symbol; kw...) where {T}

0 commit comments

Comments
 (0)