summaryrefslogtreecommitdiff
path: root/src/mf2clj/core.clj
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-10-10 21:57:28 +0800
committereltrac <hi@eltr.ac>2026-10-10 21:57:28 +0800
commit7cb4a93dbb573b8d773be05bdb157bee6c31eff1 (patch)
treef2aa2b39141266c6861d342b5e19910bd404ca13 /src/mf2clj/core.clj
parent200230b730c6de7e877af58c58c52edf1a8c5227 (diff)
clj: add type hints to reduce reflection
reduce reflection to - make program easier to build on GraalVM - improve performance
Diffstat (limited to 'src/mf2clj/core.clj')
-rw-r--r--src/mf2clj/core.clj26
1 files changed, 15 insertions, 11 deletions
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)]}