[performance] replace reduce by reduce-kv

For associative collections, using reduce-kv should
give a small performance gain over reduce as there is
no allocation of tuples for key/value pairs

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2019-05-17 00:00:22 +02:00
parent 29eeb140b9
commit 70e889a03a
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
2 changed files with 12 additions and 10 deletions

View File

@ -44,12 +44,14 @@
(defn active-chats
[contacts chats {:keys [public-key]}]
(reduce (fn [acc [chat-id {:keys [is-active] :as chat}]]
(if is-active
(assoc acc chat-id (enrich-active-chat contacts chat public-key))
acc))
{}
chats))
(reduce-kv (fn [acc chat-id {:keys [is-active] :as chat}]
(if is-active
(assoc acc
chat-id
(enrich-active-chat contacts chat public-key))
acc))
{}
chats))
(defn topic-by-current-chat
[{:keys [current-chat-id chats] :as db}]

View File

@ -177,10 +177,10 @@
(defn enrich-contacts
[contacts]
(reduce (fn [acc [public-key contact]]
(assoc acc public-key (enrich-contact contact)))
{}
contacts))
(reduce-kv (fn [acc public-key contact]
(assoc acc public-key (enrich-contact contact)))
{}
contacts))
(defn get-blocked-contacts
[contacts]