Skip to content

Commit 3c07f8e

Browse files
refactor: use new WeakCacheSet for hashconsing
1 parent 18d1791 commit 3c07f8e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/SymbolicUtils.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ import TermInterface: iscall, isexpr, head, children,
2222
import ArrayInterface
2323
import ExproniconLite as EL
2424
import TaskLocalValues: TaskLocalValue
25-
using WeakValueDicts: WeakValueDict
2625

27-
# include("WeakCacheSets.jl")
26+
function hash2 end
27+
function isequal_with_metadata end
28+
29+
include("WeakCacheSets.jl")
30+
31+
using .WeakCacheSets
2832

2933
include("cache.jl")
3034
Base.@deprecate istree iscall

src/types.jl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ end
516516
### Constructors
517517
###
518518

519-
const wvd = TaskLocalValue{WeakValueDict{UInt, BasicSymbolic}}(WeakValueDict{UInt, BasicSymbolic})
519+
const wvd = TaskLocalValue{WeakCacheSet{BasicSymbolic}}(WeakCacheSet{BasicSymbolic})
520520

521521
function generate_id()
522522
return IDType()
@@ -549,19 +549,11 @@ function BasicSymbolic(s::BasicSymbolic)::BasicSymbolic
549549
end
550550

551551
cache = wvd[]
552-
h = hash2(s)
553-
k = get!(cache, h, s)
554-
if isequal_with_metadata(k, s)
555-
if isnothing(k.id[])
556-
k.id[] = generate_id()
557-
end
558-
return k
559-
else
560-
if isnothing(s.id[])
561-
s.id[] = generate_id()
562-
end
563-
return s
552+
k = getkey!(cache, s)
553+
if k.id[] === nothing
554+
k.id[] = generate_id()
564555
end
556+
return k
565557
end
566558

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

0 commit comments

Comments
 (0)