mirror of
https://github.com/penpot/penpot.git
synced 2025-02-12 18:18:24 -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]
|
||||
(into [] (remove nil?) coll))
|
||||
|
||||
|
||||
(defn without-nils
|
||||
"Given a map, return a map removing key-value
|
||||
pairs when value is `nil`."
|
||||
([] (remove (comp nil? val)))
|
||||
([]
|
||||
(remove (comp nil? val)))
|
||||
([data]
|
||||
(into {} (without-nils) data)))
|
||||
(reduce-kv (fn [data k v]
|
||||
(if (nil? v)
|
||||
(dissoc data k)
|
||||
data))
|
||||
data
|
||||
data)))
|
||||
|
||||
(defn without-qualified
|
||||
([]
|
||||
|
|
|
@ -491,7 +491,12 @@
|
|||
the shape. The props must have :x :y :width :height."
|
||||
[{:keys [type] :as props}]
|
||||
(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)
|
||||
(:bool :path) (setup-path shape)
|
||||
:image (-> shape setup-rect setup-image)
|
||||
|
|
Loading…
Add table
Reference in a new issue