@@ -53,18 +53,16 @@ macro cached(ex)
5353 error (" cached macro can only be used on function definitions" )
5454 fcall = ex. args[1 ]
5555 if Meta. isexpr (fcall, :where )
56- hasparams = true
5756 params = fcall. args[2 : end ]
5857 fcall = fcall. args[1 ]
5958 else
60- hasparams = false
59+ params = nothing
6160 end
6261 if Meta. isexpr (fcall, :(:: ))
63- typed = true
6462 typeex = fcall. args[2 ]
6563 fcall = fcall. args[1 ]
6664 else
67- typed = false
65+ typeex = nothing
6866 end
6967 Meta. isexpr (fcall, :call ) ||
7068 error (" cached macro can only be used on function definitions" )
@@ -82,14 +80,14 @@ macro cached(ex)
8280 # actual implenetation, with underscore name
8381 _fname = Symbol (:_ , fname)
8482 _fcall = Expr (:call , _fname, fargs... )
85- if hasparams
83+ if ! isnothing (params)
8684 _fcall = Expr (:where , _fcall, params... )
8785 end
8886 _fex = Expr (:function , _fcall, _fbody)
8987
9088 # implementation that chooses the cache style
9189 newfcall = fcall
92- if hasparams
90+ if ! isnothing (params)
9391 newfcall = Expr (:where , newfcall, params... )
9492 end
9593 cachestylevar = gensym (:cachestyle )
@@ -103,11 +101,11 @@ macro cached(ex)
103101
104102 # nocache implementation
105103 fnocachecall = Expr (:call , fname, fargs... , :(:: NoCache ))
106- if hasparams
104+ if ! isnothing (params)
107105 fnocachecall = Expr (:where , fnocachecall, params... )
108106 end
109107 fnocachebody = Expr (:call , _fname, fargnames... )
110- if typed
108+ if ! isnothing (typeex)
111109 T = gensym (:T )
112110 fnocachebody = Expr (:block , Expr (:(= ), T, typeex), Expr (:(:: ), fnocachebody, T))
113111 end
@@ -116,7 +114,7 @@ macro cached(ex)
116114 # tasklocal cache implementation
117115 Dvar = gensym (:D )
118116 flocalcachecall = Expr (:call , fname, fargs... , :(:: TaskLocalCache{$Dvar} ))
119- if hasparams
117+ if ! isnothing (params)
120118 flocalcachecall = Expr (:where , flocalcachecall, params... , Dvar)
121119 else
122120 flocalcachecall = Expr (:where , flocalcachecall, Dvar)
@@ -139,7 +137,7 @@ macro cached(ex)
139137 return $ _fname ($ (fargnames... ))
140138 end
141139 )
142- if typed
140+ if ! isnothing (typeex)
143141 T = gensym (:T )
144142 flocalcachebody = Expr (
145143 :block ,
@@ -160,12 +158,12 @@ macro cached(ex)
160158
161159 # # global cache implementation
162160 fglobalcachecall = Expr (:call , fname, fargs... , :(:: GlobalLRUCache ))
163- if hasparams
161+ if ! isnothing (params)
164162 fglobalcachecall = Expr (:where , fglobalcachecall, params... )
165163 end
166164 globalcachename = Symbol (:GLOBAL_ , uppercase (string (fname)), :_CACHE )
167165 getglobalcachex = Expr (:(= ), cachevar, globalcachename)
168- if typed
166+ if ! isnothing (typeex)
169167 T = gensym (:T )
170168 fglobalcachebody = Expr (
171169 :block ,
0 commit comments