mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 05:08:23 +02:00
⚡ Implement get-handlers in term of internal reduce
That has an average performance improvement of 64% over original impl and reduction of generation of object garbage
This commit is contained in:
parent
7196be2a23
commit
1c77126fe6
4 changed files with 49 additions and 20 deletions
|
@ -340,3 +340,31 @@
|
|||
(t/is (= result4 expect1))
|
||||
(t/is (= result5 expect2))
|
||||
(t/is (= result6 expect3))))
|
||||
|
||||
|
||||
(defn get-handlers
|
||||
"Retrieve a map where for every point will retrieve a list of
|
||||
the handlers that are associated with that point.
|
||||
point -> [[index, prefix]].
|
||||
|
||||
Legacy impl"
|
||||
[content]
|
||||
(->> (d/with-prev content)
|
||||
(d/enumerate)
|
||||
(mapcat (fn [[index [cur-segment pre-segment]]]
|
||||
(if (and pre-segment (= :curve-to (:command cur-segment)))
|
||||
(let [cur-pos (path.helpers/segment->point cur-segment)
|
||||
pre-pos (path.helpers/segment->point pre-segment)]
|
||||
(-> [[pre-pos [index :c1]]
|
||||
[cur-pos [index :c2]]]))
|
||||
[])))
|
||||
|
||||
(group-by first)
|
||||
(d/mapm #(mapv second %2))))
|
||||
|
||||
(t/deftest content-to-handlers
|
||||
(let [content (path/content sample-content-large)
|
||||
result1 (get-handlers content)
|
||||
result2 (path.segment/get-handlers content)]
|
||||
|
||||
(t/is (= result1 result2))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue