mirror of
https://github.com/penpot/penpot.git
synced 2025-02-15 03:28:25 -05:00
⚡ Optimize general case of without-nils
Performance gains up to x6
This commit is contained in:
parent
944d167bbb
commit
161a55e166
2 changed files with 15 additions and 3 deletions
|
@ -216,12 +216,19 @@
|
||||||
[coll]
|
[coll]
|
||||||
(into [] (remove nil?) coll))
|
(into [] (remove nil?) coll))
|
||||||
|
|
||||||
|
|
||||||
(defn without-nils
|
(defn without-nils
|
||||||
"Given a map, return a map removing key-value
|
"Given a map, return a map removing key-value
|
||||||
pairs when value is `nil`."
|
pairs when value is `nil`."
|
||||||
([] (remove (comp nil? val)))
|
([]
|
||||||
|
(remove (comp nil? val)))
|
||||||
([data]
|
([data]
|
||||||
(into {} (without-nils) data)))
|
(reduce-kv (fn [data k v]
|
||||||
|
(if (nil? v)
|
||||||
|
(dissoc data k)
|
||||||
|
data))
|
||||||
|
data
|
||||||
|
data)))
|
||||||
|
|
||||||
(defn without-qualified
|
(defn without-qualified
|
||||||
([]
|
([]
|
||||||
|
|
|
@ -491,7 +491,12 @@
|
||||||
the shape. The props must have :x :y :width :height."
|
the shape. The props must have :x :y :width :height."
|
||||||
[{:keys [type] :as props}]
|
[{:keys [type] :as props}]
|
||||||
(let [shape (make-minimal-shape type)
|
(let [shape (make-minimal-shape type)
|
||||||
shape (merge shape (d/without-nils props))
|
|
||||||
|
;; The props can be custom records that does not
|
||||||
|
;; work properly with without-nils, so we first make
|
||||||
|
;; it plain map for proceed
|
||||||
|
props (d/without-nils (into {} props))
|
||||||
|
shape (merge shape (d/without-nils (into {} props)))
|
||||||
shape (case (:type shape)
|
shape (case (:type shape)
|
||||||
(:bool :path) (setup-path shape)
|
(:bool :path) (setup-path shape)
|
||||||
:image (-> shape setup-rect setup-image)
|
:image (-> shape setup-rect setup-image)
|
||||||
|
|
Loading…
Add table
Reference in a new issue