mirror of
https://github.com/penpot/penpot.git
synced 2025-08-02 21:18:26 +02:00
♻️ Refactor exportation process, make it considerably faster
This commit is contained in:
parent
d6abd2202c
commit
9140fc71b9
33 changed files with 1096 additions and 1090 deletions
|
@ -22,7 +22,7 @@
|
|||
java-http-clj/java-http-clj {:mvn/version "0.4.3"}
|
||||
|
||||
funcool/promesa {:mvn/version "8.0.450"}
|
||||
funcool/cuerdas {:mvn/version "2022.01.14-391"}
|
||||
funcool/cuerdas {:mvn/version "2022.03.27-397"}
|
||||
|
||||
lambdaisland/uri {:mvn/version "1.13.95"
|
||||
:exclusions [org.clojure/data.json]}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#?(:clj [clojure.core :as c]
|
||||
:cljs [cljs.core :as c])
|
||||
[app.common.data :as d]
|
||||
[cuerdas.core :as str]
|
||||
[cljs.analyzer.api :as aapi]))
|
||||
|
||||
(defmacro select-keys
|
||||
|
@ -36,61 +37,9 @@
|
|||
`(let [v# (-> ~target ~@(map (fn [key] (list `c/get key)) keys))]
|
||||
(if (some? v#) v# ~default))))
|
||||
|
||||
|
||||
;; => benchmarking: clojure.core/str
|
||||
;; --> WARM: 100000
|
||||
;; --> BENCH: 500000
|
||||
;; --> TOTAL: 197.82ms
|
||||
;; --> MEAN: 395.64ns
|
||||
;; => benchmarking: app.commons.data.macros/str
|
||||
;; --> WARM: 100000
|
||||
;; --> BENCH: 500000
|
||||
;; --> TOTAL: 20.31ms
|
||||
;; --> MEAN: 40.63ns
|
||||
|
||||
(defmacro str
|
||||
"CLJS only macro variant of `str` function that performs string concat much faster."
|
||||
([a]
|
||||
(if (:ns &env)
|
||||
(list 'js* "\"\"+~{}" a)
|
||||
(list `c/str a)))
|
||||
([a b]
|
||||
(if (:ns &env)
|
||||
(list 'js* "\"\"+~{}+~{}" a b)
|
||||
(list `c/str a b)))
|
||||
([a b c]
|
||||
(if (:ns &env)
|
||||
(list 'js* "\"\"+~{}+~{}+~{}" a b c)
|
||||
(list `c/str a b c)))
|
||||
([a b c d]
|
||||
(if (:ns &env)
|
||||
(list 'js* "\"\"+~{}+~{}+~{}+~{}" a b c d)
|
||||
(list `c/str a b c d)))
|
||||
([a b c d e]
|
||||
(if (:ns &env)
|
||||
(list 'js* "\"\"+~{}+~{}+~{}+~{}+~{}" a b c d e)
|
||||
(list `c/str a b c d e)))
|
||||
([a b c d e f]
|
||||
(if (:ns &env)
|
||||
(list 'js* "\"\"+~{}+~{}+~{}+~{}+~{}+~{}" a b c d e f)
|
||||
(list `c/str a b c d e f)))
|
||||
([a b c d e f g]
|
||||
(if (:ns &env)
|
||||
(list 'js* "\"\"+~{}+~{}+~{}+~{}+~{}+~{}+~{}" a b c d e f g)
|
||||
(list `c/str a b c d e f g)))
|
||||
([a b c d e f g h]
|
||||
(if (:ns &env)
|
||||
(list 'js* "\"\"+~{}+~{}+~{}+~{}+~{}+~{}+~{}+~{}" a b c d e f g h)
|
||||
(list `c/str a b c d e f g h)))
|
||||
([a b c d e f g h & rest]
|
||||
(let [all (into [a b c d e f g h] rest)]
|
||||
(if (:ns &env)
|
||||
(let [xf (map (fn [items] `(str ~@items)))
|
||||
pall (partition-all 8 all)]
|
||||
(if (<= (count all) 64)
|
||||
`(str ~@(sequence xf pall))
|
||||
`(c/str ~@(sequence xf pall))))
|
||||
`(c/str ~@all)))))
|
||||
[& params]
|
||||
`(str/concat ~@params))
|
||||
|
||||
(defmacro export
|
||||
"A helper macro that allows reexport a var in a current namespace."
|
||||
|
@ -129,36 +78,6 @@
|
|||
;; (.setMacro (var ~n)))
|
||||
~vr))))
|
||||
|
||||
(defn- interpolate
|
||||
[s params]
|
||||
(loop [items (->> (re-seq #"([^\%]+)*(\%(\d+)?)?" s)
|
||||
(remove (fn [[full seg]] (and (nil? seg) (not full)))))
|
||||
result []
|
||||
index 0]
|
||||
(if-let [[_ segment var? sidx] (first items)]
|
||||
(cond
|
||||
(and var? sidx)
|
||||
(let [cidx (dec (d/read-string sidx))]
|
||||
(recur (rest items)
|
||||
(-> result
|
||||
(conj segment)
|
||||
(conj (nth params cidx)))
|
||||
(inc index)))
|
||||
|
||||
var?
|
||||
(recur (rest items)
|
||||
(-> result
|
||||
(conj segment)
|
||||
(conj (nth params index)))
|
||||
(inc index))
|
||||
|
||||
:else
|
||||
(recur (rest items)
|
||||
(conj result segment)
|
||||
(inc index)))
|
||||
|
||||
(remove nil? result))))
|
||||
|
||||
(defmacro fmt
|
||||
"String interpolation helper. Can only be used with strings known at
|
||||
compile time. Can be used with indexed params access or sequential.
|
||||
|
@ -169,7 +88,7 @@
|
|||
(dm/fmt \"url(%1)\" my-url) ; indexed
|
||||
"
|
||||
[s & params]
|
||||
(cons 'app.common.data.macros/str (interpolate s (vec params))))
|
||||
`(str/ffmt ~s ~@params))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
[app.common.exceptions :as ex]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.common.spec :as us]
|
||||
[clojure.pprint :refer [pprint]]
|
||||
[cuerdas.core :as str]
|
||||
[clojure.spec.alpha :as s]
|
||||
[fipp.edn :as fpp]
|
||||
|
|
27
common/src/app/common/pprint.cljc
Normal file
27
common/src/app/common/pprint.cljc
Normal file
|
@ -0,0 +1,27 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) UXBOX Labs SL
|
||||
|
||||
(ns app.common.pprint
|
||||
(:refer-clojure :exclude [prn])
|
||||
(:require
|
||||
[cuerdas.core :as str]
|
||||
[fipp.edn :as fpp]))
|
||||
|
||||
(defn pprint-str
|
||||
[expr]
|
||||
(binding [*print-level* 8
|
||||
*print-length* 25]
|
||||
(with-out-str
|
||||
(fpp/pprint expr {:width 110}))))
|
||||
|
||||
(defn pprint
|
||||
([expr]
|
||||
(println (pprint-str expr)))
|
||||
([label expr]
|
||||
(println (str/concat "============ " label "============"))
|
||||
(pprint expr)))
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue