@@ -252,19 +252,36 @@ defmodule BACnet.Protocol.ObjectTypes.Device do
252252 @ external_resource BACstack.MixProject . get_vendor_ids_csv_file ( )
253253 @ vendor_ids BACstack.MixProject . get_vendor_ids ( )
254254
255+ # Dialyzer is so hecking stupid - go love yourself with your stupid opaqueness contracts
256+ @ dialyzer { :nowarn_function , get_vendor_ids: 0 , get_vendor_ids_arr: 0 , map_vendor_to_name: 1 }
257+
258+ @ spec get_vendor_ids_arr ( ) :: :array . array ( String . t ( ) )
259+ defp get_vendor_ids_arr ( ) , do: @ vendor_ids
260+
255261 @ doc """
256262 Get the list of known vendor IDs to vendor names.
263+
264+ > #### Implementation Detail {: .info}
265+ > Internally the vendor IDs mapping is represented as an erlang array
266+ > and will be converted to a map. If you use this map multiple times in a row,
267+ > consider storing it in a variable as the conversion can be computational heavy.
257268 """
258269 @ spec get_vendor_ids ( ) :: % { optional ( non_neg_integer ( ) ) => String . t ( ) }
259270 def get_vendor_ids ( ) do
260- @ vendor_ids
271+ get_vendor_ids_arr ( )
272+ |> :array . sparse_to_orddict ( )
273+ |> Map . new ( )
261274 end
262275
263- @ spec map_vendor_to_name ( non_neg_integer ) :: String . t ( )
264- defp map_vendor_to_name ( id ) do
265- Map . get ( @ vendor_ids , id , "" )
276+ @ spec map_vendor_to_name ( non_neg_integer ( ) ) :: String . t ( )
277+ defp map_vendor_to_name ( id )
278+
279+ defp map_vendor_to_name ( id ) when is_integer ( id ) and id >= 0 do
280+ :array . get ( id , get_vendor_ids_arr ( ) )
266281 end
267282
283+ defp map_vendor_to_name ( _id ) , do: ""
284+
268285 @ spec inhibit_object_check ( t ( ) ) :: { :ok , t ( ) }
269286 defp inhibit_object_check ( obj ) do
270287 # Only patch vendor name if empty
0 commit comments