From 7cb4a93dbb573b8d773be05bdb157bee6c31eff1 Mon Sep 17 00:00:00 2001 From: eltrac Date: Sat, 10 Oct 2026 21:57:28 +0800 Subject: clj: add type hints to reduce reflection reduce reflection to - make program easier to build on GraalVM - improve performance --- src/mf2clj/core.clj | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/mf2clj/core.clj b/src/mf2clj/core.clj index f049222..2d67e2f 100644 --- a/src/mf2clj/core.clj +++ b/src/mf2clj/core.clj @@ -5,23 +5,27 @@ (:import [org.extism.sdk.chicory Manifest ManifestWasm Plugin] [java.nio.charset StandardCharsets])) -(defn- manifest-from-wasm [wasm] - (Manifest/ofWasms (into-array ManifestWasm [wasm]))) - (def plugin - (-> "mf2go.wasm" io/resource io/input-stream .readAllBytes - ManifestWasm/fromBytes .build - manifest-from-wasm .build - Plugin/ofManifest .build)) + (let [^ManifestWasm wasm-manifest + (-> "mf2go.wasm" io/resource io/input-stream .readAllBytes + ManifestWasm/fromBytes + .build) + ^Manifest manifest + (-> (into-array ManifestWasm [wasm-manifest]) + Manifest/ofWasms + .build)] + (-> manifest + Plugin/ofManifest + .build))) (def charset StandardCharsets/UTF_8) (defn parse-bytes [html-bytes] {:pre [(bytes? html-bytes)]} - (-> (.call plugin "parse" html-bytes) - (String. charset) - json/parse-string - keywordize-keys)) + (let [^bytes result (.call ^Plugin plugin "parse" html-bytes)] + (-> (String. result charset) + json/parse-string + keywordize-keys))) (defn parse [^String html-string] {:pre [(string? html-string)]} -- cgit v1.2.3