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 : Dict String WhatToDo -> Dict String WhatToDo -> Dict String WhatToDo
combineReducedDicts dict1 dict2 = combineReducedDicts dict1 dict2 =
(Dict.toList dict1 ++ Dict.toList dict2) if Dict.size dict1 > Dict.size dict2 then
|> fromListDedupe Pages.StaticHttpRequest.merge uniqueInsertAll dict2 dict1
else
uniqueInsertAll dict1 dict2
fromListDedupe : (comparable -> a -> a -> a) -> List ( comparable, a ) -> Dict comparable a uniqueInsertAll : Dict String WhatToDo -> Dict String WhatToDo -> Dict String WhatToDo
fromListDedupe combineFn xs = uniqueInsertAll dictToDedupeMerge startingDict =
List.foldl Dict.foldl
(\( key, value ) acc -> Dict.Extra.insertDedupe (combineFn key) key value acc) (\key value acc -> Dict.Extra.insertDedupe (Pages.StaticHttpRequest.merge key) key value acc)
Dict.empty startingDict
xs dictToDedupeMerge
lookup : KeepOrDiscard -> ApplicationType -> DataSource value -> RequestsAndPending -> Result Pages.StaticHttpRequest.Error ( Dict String WhatToDo, value ) lookup : KeepOrDiscard -> ApplicationType -> DataSource value -> RequestsAndPending -> Result Pages.StaticHttpRequest.Error ( Dict String WhatToDo, value )