[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 (defn active-chats
[contacts chats {:keys [public-key]}] [contacts chats {:keys [public-key]}]
(reduce (fn [acc [chat-id {:keys [is-active] :as chat}]] (reduce-kv (fn [acc chat-id {:keys [is-active] :as chat}]
(if is-active (if is-active
(assoc acc chat-id (enrich-active-chat contacts chat public-key)) (assoc acc
acc)) chat-id
{} (enrich-active-chat contacts chat public-key))
chats)) acc))
{}
chats))
(defn topic-by-current-chat (defn topic-by-current-chat
[{:keys [current-chat-id chats] :as db}] [{:keys [current-chat-id chats] :as db}]

View File

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