Skip to content

Commit 1e46b57

Browse files
feat: sizehint! in @cache macro
1 parent d4fa06d commit 1e46b57

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/cache.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ resets the stats.
102102
function clear_cache!(fn)
103103
dict, stats = associated_cache(fn).tlv[]
104104
empty!(dict)
105+
sizehint!(dict, get_limit(fn))
105106
reset_stats!(stats)
106107
end
107108

@@ -339,7 +340,7 @@ macro cache(args...)
339340
end)
340341

341342
# instantiation of the TaskLocalValue
342-
tlvctor = :($tlvT(() -> ($cacheT(), $CacheStats())))
343+
tlvctor = :($tlvT(() -> ((dict = $cacheT(); sizehint!(dict, $get_limit($name)); dict), $CacheStats())))
343344
# instantiation expression for the constant value
344345
cachector = Expr(:call, structT, tlvctor, config[:limit], config[:retain_fraction], config[:enabled])
345346

0 commit comments

Comments
 (0)