diff --git a/backend/src/app/binfile/v3.clj b/backend/src/app/binfile/v3.clj index f66a4da539..4e43f07b92 100644 --- a/backend/src/app/binfile/v3.clj +++ b/backend/src/app/binfile/v3.clj @@ -41,8 +41,10 @@ [datoteka.fs :as fs] [datoteka.io :as io]) (:import + java.io.File java.io.InputStream java.io.OutputStreamWriter + java.lang.AutoCloseable java.util.zip.ZipEntry java.util.zip.ZipFile java.util.zip.ZipOutputStream)) @@ -251,9 +253,9 @@ (write-entry! output path params) (with-open [input (sto/get-object-data storage sobject)] - (.putNextEntry output (ZipEntry. (str "objects/" id ext))) + (.putNextEntry ^ZipOutputStream output (ZipEntry. (str "objects/" id ext))) (io/copy input output :size (:size sobject)) - (.closeEntry output)))))) + (.closeEntry ^ZipOutputStream output)))))) (defn- export-file [{:keys [::file-id ::output] :as cfg}] @@ -447,7 +449,7 @@ (defn- read-manifest [^ZipFile input] (let [entry (get-zip-entry input "manifest.json")] - (with-open [reader (zip-entry-reader input entry)] + (with-open [^AutoCloseable reader (zip-entry-reader input entry)] (let [manifest (json/read reader :key-fn json/read-kebab-key)] (decode-manifest manifest))))) @@ -537,12 +539,12 @@ (defn- read-entry [^ZipFile input entry] - (with-open [reader (zip-entry-reader input entry)] + (with-open [^AutoCloseable reader (zip-entry-reader input entry)] (json/read reader :key-fn json/read-kebab-key))) (defn- read-plain-entry [^ZipFile input entry] - (with-open [reader (zip-entry-reader input entry)] + (with-open [^AutoCloseable reader (zip-entry-reader input entry)] (json/read reader))) (defn- read-file @@ -1006,8 +1008,8 @@ (try (l/info :hint "start exportation" :export-id (str id)) (binding [bfc/*state* (volatile! (bfc/initial-state))] - (with-open [output (io/output-stream output)] - (with-open [output (ZipOutputStream. output)] + (with-open [^AutoCloseable output (io/output-stream output)] + (with-open [^AutoCloseable output (ZipOutputStream. output)] (let [cfg (assoc cfg ::output output)] (export-files cfg) (export-storage-objects cfg))))) @@ -1051,7 +1053,7 @@ (l/info :hint "import: started" :id (str id)) (try - (with-open [input (ZipFile. (fs/file input))] + (with-open [input (ZipFile. ^File (fs/file input))] (import-files (assoc cfg ::bfc/input input))) (catch Throwable cause @@ -1066,6 +1068,6 @@ (defn get-manifest [path] - (with-open [input (ZipFile. (fs/file path))] + (with-open [^AutoCloseable input (ZipFile. ^File (fs/file path))] (-> (read-manifest input) (validate-manifest)))) diff --git a/backend/src/app/http/sse.clj b/backend/src/app/http/sse.clj index 7459d9224b..8d431cc93c 100644 --- a/backend/src/app/http/sse.clj +++ b/backend/src/app/http/sse.clj @@ -33,7 +33,7 @@ (println "event:" (d/name name)) (println "data:" (t/encode-str data {:type :json-verbose})) (println))] - (.getBytes data "UTF-8")) + (.getBytes ^String data "UTF-8")) (catch Throwable cause (l/err :hint "unexpected error on encoding value on sse stream" :cause cause) diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index 52f89668b1..350bd1bdc5 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -116,7 +116,7 @@ (defn- parse-svg [text] (let [text (strip-doctype text)] - (dm/with-open [istream (IOUtils/toInputStream text "UTF-8")] + (dm/with-open [istream (IOUtils/toInputStream ^String text "UTF-8")] (xml/parse istream secure-parser-factory)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/backend/src/app/storage/gc_touched.clj b/backend/src/app/storage/gc_touched.clj index 45d4594292..199d0c6b74 100644 --- a/backend/src/app/storage/gc_touched.clj +++ b/backend/src/app/storage/gc_touched.clj @@ -212,8 +212,8 @@ deleted 0] (if-let [chunk (get-chunk pool)] (let [[nfo ndo] (db/tx-run! cfg process-chunk! chunk)] - (recur (+ freezed nfo) - (+ deleted ndo))) + (recur (long (+ freezed nfo)) + (long (+ deleted ndo)))) (do (l/inf :hint "task finished" :to-freeze freezed diff --git a/backend/src/app/tasks/objects_gc.clj b/backend/src/app/tasks/objects_gc.clj index b44286e3dd..319ef2f526 100644 --- a/backend/src/app/tasks/objects_gc.clj +++ b/backend/src/app/tasks/objects_gc.clj @@ -313,7 +313,7 @@ (db/exec-one! conn ["SET LOCAL rules.deletion_protection TO off"]) (proc-fn cfg)))] (if (pos? result) - (recur (+ total result)) + (recur (long (+ total result))) total)))) (defmethod ig/assert-key ::handler @@ -335,7 +335,7 @@ (if-let [proc-fn (first procs)] (let [result (execute-proc! cfg proc-fn)] (recur (rest procs) - (+ total result))) + (long (+ total result)))) (do (l/inf :hint "task finished" :deleted total) {:processed total})))))) diff --git a/common/src/app/common/buffer.cljc b/common/src/app/common/buffer.cljc index 8e563cd4fe..c04bd46239 100644 --- a/common/src/app/common/buffer.cljc +++ b/common/src/app/common/buffer.cljc @@ -20,42 +20,42 @@ (if (:ns &env) `(.getInt8 ~target ~offset true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(long (.get ~target ~offset))))) + `(long (.get ~target (unchecked-int ~offset)))))) (defmacro read-unsigned-byte [target offset] (if (:ns &env) `(.getUint8 ~target ~offset true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(bit-and (long (.get ~target ~offset)) 0xff)))) + `(bit-and (long (.get ~target (unchecked-int ~offset))) 0xff)))) (defmacro read-bool [target offset] (if (:ns &env) `(== 1 (.getInt8 ~target ~offset true)) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(== 1 (.get ~target ~offset))))) + `(== 1 (.get ~target (unchecked-int ~offset)))))) (defmacro read-short [target offset] (if (:ns &env) `(.getInt16 ~target ~offset true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(.getShort ~target ~offset)))) + `(.getShort ~target (unchecked-int ~offset))))) (defmacro read-int [target offset] (if (:ns &env) `(.getInt32 ~target ~offset true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(long (.getInt ~target ~offset))))) + `(long (.getInt ~target (unchecked-int ~offset)))))) (defmacro read-float [target offset] (if (:ns &env) `(.getFloat32 ~target ~offset true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(double (.getFloat ~target ~offset))))) + `(double (.getFloat ~target (unchecked-int ~offset)))))) (defmacro read-uuid [target offset] @@ -69,8 +69,8 @@ (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] `(try (.order ~target ByteOrder/BIG_ENDIAN) - (let [msb# (.getLong ~target (+ ~offset 0)) - lsb# (.getLong ~target (+ ~offset 8))] + (let [msb# (.getLong ~target (unchecked-int (+ ~offset 0))) + lsb# (.getLong ~target (unchecked-int (+ ~offset 8)))] (java.util.UUID. (long msb#) (long lsb#))) (finally (.order ~target ByteOrder/LITTLE_ENDIAN)))))) @@ -80,7 +80,7 @@ (if (:ns &env) `(.setInt8 ~target ~offset ~value true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(.put ~target ~offset (unchecked-byte ~value))))) + `(.put ~target (unchecked-int ~offset) (unchecked-byte ~value))))) (defmacro write-u8 [target offset value] @@ -94,21 +94,21 @@ (if (:ns &env) `(.setInt8 ~target ~offset (if ~value 0x01 0x00) true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(.put ~target ~offset (unchecked-byte (if ~value 0x01 0x00)))))) + `(.put ~target (unchecked-int ~offset) (unchecked-byte (if ~value 0x01 0x00)))))) (defmacro write-short [target offset value] (if (:ns &env) `(.setInt16 ~target ~offset ~value true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(.putShort ~target ~offset (unchecked-short ~value))))) + `(.putShort ~target (unchecked-int ~offset) (unchecked-short ~value))))) (defmacro write-int [target offset value] (if (:ns &env) `(.setInt32 ~target ~offset ~value true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(.putInt ~target ~offset (unchecked-int ~value))))) + `(.putInt ~target (unchecked-int ~offset) (unchecked-int ~value))))) (defmacro write-u32 [target offset value] @@ -127,7 +127,7 @@ (if (:ns &env) `(.setFloat32 ~target ~offset ~value true) (let [target (with-meta target {:tag 'java.nio.ByteBuffer})] - `(.putFloat ~target ~offset (unchecked-float ~value))))) + `(.putFloat ~target (unchecked-int ~offset) (unchecked-float ~value))))) (defmacro write-f32 "Idiomatic alias for `write-float`." @@ -147,8 +147,8 @@ value (with-meta value {:tag 'java.util.UUID})] `(try (.order ~target ByteOrder/BIG_ENDIAN) - (.putLong ~target (+ ~offset 0) (.getMostSignificantBits ~value)) - (.putLong ~target (+ ~offset 8) (.getLeastSignificantBits ~value)) + (.putLong ~target (unchecked-int (+ ~offset 0)) (.getMostSignificantBits ~value)) + (.putLong ~target (unchecked-int (+ ~offset 8)) (.getLeastSignificantBits ~value)) (finally (.order ~target ByteOrder/LITTLE_ENDIAN)))))) diff --git a/common/src/app/common/geom/matrix.cljc b/common/src/app/common/geom/matrix.cljc index 954c13ccca..63195b1bb5 100644 --- a/common/src/app/common/geom/matrix.cljc +++ b/common/src/app/common/geom/matrix.cljc @@ -25,16 +25,7 @@ ;; --- Matrix Impl -(defn format-precision - [mtx precision] - (when mtx - (dm/fmt "matrix(%, %, %, %, %, %)" - (mth/to-fixed (.-a mtx) precision) - (mth/to-fixed (.-b mtx) precision) - (mth/to-fixed (.-c mtx) precision) - (mth/to-fixed (.-d mtx) precision) - (mth/to-fixed (.-e mtx) precision) - (mth/to-fixed (.-f mtx) precision)))) +(declare format-precision) (cr/defrecord Matrix [^double a ^double b @@ -46,6 +37,17 @@ (toString [this] (format-precision this precision))) +(defn format-precision + [mtx precision] + (when mtx + (dm/fmt "matrix(%, %, %, %, %, %)" + (mth/to-fixed (.-a ^Matrix mtx) precision) + (mth/to-fixed (.-b ^Matrix mtx) precision) + (mth/to-fixed (.-c ^Matrix mtx) precision) + (mth/to-fixed (.-d ^Matrix mtx) precision) + (mth/to-fixed (.-e ^Matrix mtx) precision) + (mth/to-fixed (.-f ^Matrix mtx) precision)))) + (defn matrix? "Return true if `v` is Matrix instance." [v] diff --git a/common/src/app/common/geom/modifiers.cljc b/common/src/app/common/geom/modifiers.cljc index bd6253e46f..01ade1dd61 100644 --- a/common/src/app/common/geom/modifiers.cljc +++ b/common/src/app/common/geom/modifiers.cljc @@ -99,7 +99,7 @@ [_ modif-tree] (reduce set-child-modifiers [layout-line modif-tree] children)] - (recur modif-tree (first pending) (rest pending) to-idx)) + (recur modif-tree (first pending) (rest pending) (long to-idx))) modif-tree))))) diff --git a/common/src/app/common/geom/rect.cljc b/common/src/app/common/geom/rect.cljc index b7d14d5426..925c784e65 100644 --- a/common/src/app/common/geom/rect.cljc +++ b/common/src/app/common/geom/rect.cljc @@ -255,10 +255,10 @@ (if-let [pt (first pts)] (let [x (dm/get-prop pt :x) y (dm/get-prop pt :y)] - (recur (mth/min minx x) - (mth/min miny y) - (mth/max maxx x) - (mth/max maxy y) + (recur (double (mth/min minx x)) + (double (mth/min miny y)) + (double (mth/max maxx x)) + (double (mth/max maxy y)) (rest pts))) (when (d/num? minx miny maxx maxy) (make-rect minx miny (- maxx minx) (- maxy miny))))))) diff --git a/common/src/app/common/geom/shapes/flex_layout/drop_area.cljc b/common/src/app/common/geom/shapes/flex_layout/drop_area.cljc index e9a5fa4915..9bb428c2b1 100644 --- a/common/src/app/common/geom/shapes/flex_layout/drop_area.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/drop_area.cljc @@ -177,7 +177,7 @@ (rest children)))))] (recur next-areas - (+ from-idx (:num-children current-line)) + (+ from-idx (long (:num-children current-line))) (+ (:x line-area) (:width line-area)) (+ (:y line-area) (:height line-area)) (rest lines))))))) diff --git a/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc b/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc index 1ec6bffd5a..639da86514 100644 --- a/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc +++ b/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc @@ -393,7 +393,7 @@ min-fr (let [{:keys [size type value]} (first tracks) min-fr (if (= type :flex) (max min-fr (/ size value)) min-fr)] - (recur (rest tracks) min-fr))))) + (recur (rest tracks) (double min-fr)))))) (defn calc-layout-data ([parent transformed-parent-bounds children bounds objects] diff --git a/common/src/app/common/types/path/helpers.cljc b/common/src/app/common/types/path/helpers.cljc index 1f1218efd9..e7ef6c6336 100644 --- a/common/src/app/common/types/path/helpers.cljc +++ b/common/src/app/common/types/path/helpers.cljc @@ -403,7 +403,7 @@ (if (>= to 1) result - (recur to result)))))) + (recur (long to) result)))))) (defn curve-split "Splits a curve into two at the given parametric value `t`. diff --git a/common/src/app/common/types/path/subpath.cljc b/common/src/app/common/types/path/subpath.cljc index b7f13a0aea..6082117cae 100644 --- a/common/src/app/common/types/path/subpath.cljc +++ b/common/src/app/common/types/path/subpath.cljc @@ -190,4 +190,4 @@ (recur (first subpath) (rest subpath) first-point - signed-area)))))) + (long signed-area))))))) diff --git a/common/test/common_tests/geom_shapes_test.cljc b/common/test/common_tests/geom_shapes_test.cljc index 3164e37d41..29401412ec 100644 --- a/common/test/common_tests/geom_shapes_test.cljc +++ b/common/test/common_tests/geom_shapes_test.cljc @@ -168,7 +168,7 @@ (gpt/point 20 65.2) (gpt/point 12 -10)] result (grc/points->rect points) - expect {:x -1, :y -10, :width 21, :height 75.2}] + expect {:x -1.0, :y -10.0, :width 21.0, :height 75.2}] (t/is (= (:x expect) (:x result))) (t/is (= (:y expect) (:y result)))