From a5c24499c82c7491ae1ec8fe3f2435aaca749056 Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Mon, 14 Oct 2024 13:03:01 +0300 Subject: [PATCH 1/3] Get rid of String/valueOf Tests fail if I don't keep the or --- src/hiccup/compiler.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hiccup/compiler.clj b/src/hiccup/compiler.clj index e1db82f..98b723c 100644 --- a/src/hiccup/compiler.clj +++ b/src/hiccup/compiler.clj @@ -45,7 +45,7 @@ 1 (let [arg (first strs)] (if (string? arg) arg - `(String/valueOf (or ~arg "")))) + `(str (or ~arg "")))) `(let [~w (StringBuilder.)] ~@(map (fn [arg] (if (string? arg) From 830837077e4b487e93b93555d6c4477fd0d1a95b Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Mon, 14 Oct 2024 13:04:06 +0300 Subject: [PATCH 2/3] Use subs instead of .substring --- src/hiccup/compiler.clj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hiccup/compiler.clj b/src/hiccup/compiler.clj index 98b723c..48a95d2 100644 --- a/src/hiccup/compiler.clj +++ b/src/hiccup/compiler.clj @@ -117,15 +117,15 @@ (let [id-index (let [index (.indexOf tag "#")] (when (pos? index) index)) class-index (let [index (.indexOf tag ".")] (when (pos? index) index))] [(cond - id-index (.substring tag 0 id-index) - class-index (.substring tag 0 class-index) + id-index (subs tag 0 id-index) + class-index (subs tag 0 class-index) :else tag) (when id-index (if class-index - (.substring tag (unchecked-inc-int id-index) class-index) - (.substring tag (unchecked-inc-int id-index)))) + (subs tag (unchecked-inc-int id-index) class-index) + (subs tag (unchecked-inc-int id-index)))) (when class-index - (.substring tag (unchecked-inc-int class-index)))])) + (subs tag (unchecked-inc-int class-index)))])) (defn merge-classes [class classes] (cond From 6769bde06b0038d8d2316e7ac29f3568f666b4e6 Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Mon, 14 Oct 2024 13:32:38 +0300 Subject: [PATCH 3/3] Use clojure.string/index-of when available --- src/hiccup/compiler.clj | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hiccup/compiler.clj b/src/hiccup/compiler.clj index 48a95d2..722eb55 100644 --- a/src/hiccup/compiler.clj +++ b/src/hiccup/compiler.clj @@ -112,10 +112,16 @@ (or content (and (html-mode?) (not (void-tags tag))))) - -(defn- parse-tag [^String tag] - (let [id-index (let [index (.indexOf tag "#")] (when (pos? index) index)) - class-index (let [index (.indexOf tag ".")] (when (pos? index) index))] +(def str-index-of + (or (resolve 'str/index-of) + (fn [^String tag ^String value] + (let [index (.indexOf tag value)] + (when (pos? index) + index))))) + +(defn- parse-tag [tag] + (let [id-index (str-index-of tag "#") + class-index (str-index-of tag ".")] [(cond id-index (subs tag 0 id-index) class-index (subs tag 0 class-index)