11function map_lookup_elem (map:: RTMap{Name,MT,K,V,ME,F} , key:: K ) where {Name,MT,K,V,ME,F}
2- keyref = Ref {K} ( key)
2+ keyref = ZeroInitRef (K, key)
33 GC. @preserve keyref begin
4- _map_lookup_elem (map, Base. unsafe_convert (Ptr{K}, keyref))
4+ keyref_ptr = Base. unsafe_convert (Ptr{K}, keyref)
5+ _map_lookup_elem (map, keyref_ptr)
56 end
67end
7- function map_update_elem (map:: RTMap{Name,MT,K,V,ME,F} , key:: K , value:: V , flags:: UInt64 ) where {Name,MT,K,V,ME,F}
8- keyref = Ref {K} ( key)
9- valref = Ref {V} ( value)
8+ @inline function map_update_elem (map:: RTMap{Name,MT,K,V,ME,F} , key:: K , value:: V , flags:: UInt64 ) where {Name,MT,K,V,ME,F}
9+ keyref = ZeroInitRef (K, key)
10+ valref = ZeroInitRef (V, value)
1011 GC. @preserve keyref valref begin
11- _map_update_elem (map,
12- Base. unsafe_convert (Ptr{K}, keyref),
13- Base. unsafe_convert (Ptr{V}, valref),
14- flags)
12+ keyref_ptr = Base. unsafe_convert (Ptr{K}, keyref)
13+ valref_ptr = Base. unsafe_convert (Ptr{V}, valref)
14+ _map_update_elem (map, keyref_ptr, valref_ptr, flags)
1515 end
1616end
1717function map_delete_elem (map:: RTMap{Name,MT,K,V,ME,F} , key:: K ) where {Name,MT,K,V,ME,F}
18- keyref = Ref {K} ( key)
18+ keyref = ZeroInitRef (K, key)
1919 GC. @preserve keyref begin
20+ keyref_ptr = Base. unsafe_convert (Ptr{K}, keyref)
2021 _map_delete_elem (map, Base. unsafe_convert (Ptr{K}, keyref))
2122 end
2223end
24+
25+ # TODO : Use bpfcall
2326@generated function _map_lookup_elem (map:: RTMap{Name,MT,K,V,ME,F} , key:: Ptr{K} ) where {Name,MT,K,V,ME,F}
2427 JuliaContext () do ctx
2528 T_keyp = LLVM. PointerType (convert (LLVMType, K, ctx))
@@ -125,15 +128,15 @@ end
125128@inline Base. getindex (map:: RTMap{Name,MT,K,V,ME,F} , idx) where {Name,MT,K,V,ME,F} =
126129 getindex (map, bpfconvert (K, idx))
127130Base. getindex (map:: RTMap , :: Nothing ) = nothing
128- function Base. getindex (map:: AbstractHashMap{Name,MT,K,V,ME,F} , idx:: K ) where {Name,MT,K,V,ME,F}
131+ @inline function Base. getindex (map:: AbstractHashMap{Name,MT,K,V,ME,F} , idx:: K ) where {Name,MT,K,V,ME,F}
129132 ptr = map_lookup_elem (map, idx)
130133 if reinterpret (UInt64, ptr) > 0
131134 return unsafe_load (ptr)
132135 else
133136 return nothing
134137 end
135138end
136- function Base. getindex (map:: AbstractArrayMap{Name,MT,K,V,ME,F} , idx:: K ) where {Name,MT,K,V,ME,F}
139+ @inline function Base. getindex (map:: AbstractArrayMap{Name,MT,K,V,ME,F} , idx:: K ) where {Name,MT,K,V,ME,F}
137140 if idx > 0
138141 ptr = map_lookup_elem (map, idx- K (1 ))
139142 if reinterpret (UInt64, ptr) > 0
@@ -148,14 +151,14 @@ end
148151
149152@inline Base. setindex! (map:: RTMap{Name,MT,K,V,ME,F} , value, idx) where {Name,MT,K,V,ME,F} =
150153 setindex! (map, bpfconvert (V, value), bpfconvert (K, idx))
151- Base. setindex! (map:: RTMap , :: Nothing , idx) = nothing
152- Base. setindex! (map:: RTMap , value, :: Nothing ) = nothing
153- Base. setindex! (map:: RTMap , :: Nothing , :: Nothing ) = nothing
154- function Base. setindex! (map:: AbstractHashMap{Name,MT,K,V,ME,F} , value:: V , idx:: K ) where {Name,MT,K,V,ME,F}
154+ @inline Base. setindex! (map:: RTMap , :: Nothing , idx) = nothing
155+ @inline Base. setindex! (map:: RTMap , value, :: Nothing ) = nothing
156+ @inline Base. setindex! (map:: RTMap , :: Nothing , :: Nothing ) = nothing
157+ @inline function Base. setindex! (map:: AbstractHashMap{Name,MT,K,V,ME,F} , value:: V , idx:: K ) where {Name,MT,K,V,ME,F}
155158 map_update_elem (map, idx, value, UInt64 (0 ))
156159 value
157160end
158- function Base. setindex! (map:: AbstractArrayMap{Name,MT,K,V,ME,F} , value:: V , idx:: K ) where {Name,MT,K,V,ME,F}
161+ @inline function Base. setindex! (map:: AbstractArrayMap{Name,MT,K,V,ME,F} , value:: V , idx:: K ) where {Name,MT,K,V,ME,F}
159162 if idx > 0
160163 map_update_elem (map, idx- K (1 ), value, UInt64 (0 ))
161164 end
@@ -176,18 +179,18 @@ end
176179 map
177180end
178181
179- Base. haskey (map:: AbstractHashMap{Name,MT,K,V,ME,F} , idx) where {Name,MT,K,V,ME,F} =
182+ @inline Base. haskey (map:: AbstractHashMap{Name,MT,K,V,ME,F} , idx) where {Name,MT,K,V,ME,F} =
180183 map[bpfconvert (K, idx)] != = nothing
181- Base. haskey (map:: RTMap , :: Nothing ) = false
182- function Base. haskey (map:: AbstractArrayMap{Name,MT,K,V,ME,F} , idx) where {Name,MT,K,V,ME,F}
184+ @inline Base. haskey (map:: RTMap , :: Nothing ) = false
185+ @inline function Base. haskey (map:: AbstractArrayMap{Name,MT,K,V,ME,F} , idx) where {Name,MT,K,V,ME,F}
183186 if idx > 0
184187 map[bpfconvert (K, idx)- K (1 )] != = nothing
185188 else
186189 false
187190 end
188191end
189192
190- function Base. get (map:: RTMap{Name,MT,K,V,ME,F} , k:: K , v:: V ) where {Name,MT,K,V,ME,F}
193+ @inline function Base. get (map:: RTMap{Name,MT,K,V,ME,F} , k:: K , v:: V ) where {Name,MT,K,V,ME,F}
191194 map_v = map[k]
192195 if map_v != = nothing
193196 return map_v
0 commit comments