Avoid Dict to List conversions to improve performance.

This commit is contained in:
Dillon Kearns 2021-08-09 09:29:57 -07:00
parent 56dec4752c
commit 78746c1195

View File

@ -481,16 +481,19 @@ It would not work correctly if it chose between two responses that were reduced
-}
combineReducedDicts : Dict String WhatToDo -> Dict String WhatToDo -> Dict String WhatToDo
combineReducedDicts dict1 dict2 =
(Dict.toList dict1 ++ Dict.toList dict2)
|> fromListDedupe Pages.StaticHttpRequest.merge
if Dict.size dict1 > Dict.size dict2 then
uniqueInsertAll dict2 dict1
else
uniqueInsertAll dict1 dict2
fromListDedupe : (comparable -> a -> a -> a) -> List ( comparable, a ) -> Dict comparable a
fromListDedupe combineFn xs =
List.foldl
(\( key, value ) acc -> Dict.Extra.insertDedupe (combineFn key) key value acc)
Dict.empty
xs
uniqueInsertAll : Dict String WhatToDo -> Dict String WhatToDo -> Dict String WhatToDo
uniqueInsertAll dictToDedupeMerge startingDict =
Dict.foldl
(\key value acc -> Dict.Extra.insertDedupe (Pages.StaticHttpRequest.merge key) key value acc)
startingDict
dictToDedupeMerge
lookup : KeepOrDiscard -> ApplicationType -> DataSource value -> RequestsAndPending -> Result Pages.StaticHttpRequest.Error ( Dict String WhatToDo, value )