mirror of
https://github.com/penpot/penpot.git
synced 2026-08-05 04:18:41 +00:00
✨ Reduce compexity on set-shape-children wasm api method
This commit is contained in:
parent
ba42c9b85e
commit
027e5c64cc
@ -49,7 +49,10 @@
|
|||||||
;; All of these entries are in bytes so we need to adjust
|
;; All of these entries are in bytes so we need to adjust
|
||||||
;; these values to work with TypedArrays of 32 bits.
|
;; these values to work with TypedArrays of 32 bits.
|
||||||
;;
|
;;
|
||||||
(def UUID-BYTE-SIZE 16)
|
(def ^:const UUID-BYTE-SIZE 16)
|
||||||
|
(def ^:const UUID-U32-SIZE (/ UUID-BYTE-SIZE 4))
|
||||||
|
|
||||||
|
|
||||||
(def MODIFIER-ENTRY-SIZE 40)
|
(def MODIFIER-ENTRY-SIZE 40)
|
||||||
(def MODIFIER-ENTRY-TRANSFORM-OFFSET 16)
|
(def MODIFIER-ENTRY-TRANSFORM-OFFSET 16)
|
||||||
(def GRID-LAYOUT-ROW-ENTRY-SIZE 5)
|
(def GRID-LAYOUT-ROW-ENTRY-SIZE 5)
|
||||||
@ -171,25 +174,25 @@
|
|||||||
(h/call wasm/internal-module "_set_shape_rotation" rotation))
|
(h/call wasm/internal-module "_set_shape_rotation" rotation))
|
||||||
|
|
||||||
(defn set-shape-children
|
(defn set-shape-children
|
||||||
[shape-ids]
|
[children]
|
||||||
(let [num-shapes (count shape-ids)]
|
(let [heap (mem/get-heap-u32)
|
||||||
|
length (count children)]
|
||||||
(perf/begin-measure "set-shape-children")
|
(perf/begin-measure "set-shape-children")
|
||||||
(when (> num-shapes 0)
|
(when (pos? length)
|
||||||
(let [offset (mem/alloc-bytes (* UUID-BYTE-SIZE num-shapes))
|
(let [offset (mem/alloc-bytes-32 (* UUID-BYTE-SIZE length))]
|
||||||
heap (mem/get-heap-u32)]
|
(reduce (fn [offset id]
|
||||||
|
(sr/heapu32-set-uuid id heap offset)
|
||||||
(loop [entries (seq shape-ids)
|
(+ offset UUID-U32-SIZE))
|
||||||
current-offset offset]
|
offset
|
||||||
(when-not (empty? entries)
|
children)))
|
||||||
(let [id (first entries)]
|
|
||||||
(sr/heapu32-set-uuid id heap (mem/ptr8->ptr32 current-offset))
|
|
||||||
(recur (rest entries) (+ current-offset UUID-BYTE-SIZE)))))))
|
|
||||||
|
|
||||||
(let [result (h/call wasm/internal-module "_set_children")]
|
(let [result (h/call wasm/internal-module "_set_children")]
|
||||||
(perf/end-measure "set-shape-children")
|
(perf/end-measure "set-shape-children")
|
||||||
result)))
|
result)))
|
||||||
|
|
||||||
(defn- get-string-length [string] (+ (count string) 1))
|
(defn- get-string-length
|
||||||
|
[string]
|
||||||
|
(+ (count string) 1))
|
||||||
|
|
||||||
(defn- fetch-image
|
(defn- fetch-image
|
||||||
[shape-id image-id]
|
[shape-id image-id]
|
||||||
@ -1081,7 +1084,7 @@
|
|||||||
|
|
||||||
(reduce (fn [offset id]
|
(reduce (fn [offset id]
|
||||||
(sr/heapu32-set-uuid id heap offset)
|
(sr/heapu32-set-uuid id heap offset)
|
||||||
(+ offset (/ UUID-BYTE-SIZE 4)))
|
(+ offset UUID-U32-SIZE))
|
||||||
offset
|
offset
|
||||||
(rseq ids)))
|
(rseq ids)))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user