Skip to content

Commit

Permalink
Optimize compile-element ::literal-tag to emit the element content …
Browse files Browse the repository at this point in the history
…only once
  • Loading branch information
luontola committed Nov 28, 2023
1 parent 3210c28 commit 6fef3a6
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/hiccup/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -335,21 +335,22 @@
(let [[tag tag-attrs _] (normalize-element-form [tag])
attrs-sym (gensym "attrs")]
`(let [~attrs-sym ~attrs]
(if (map? ~attrs-sym)
~(if (container-tag? tag content)
`(build-string ~(str "<" tag)
(render-attr-map (merge ~tag-attrs ~attrs-sym)) ">"
;; tail
~@(compile-seq content)
~(str "</" tag ">"))
`(build-string ~(str "<" tag)
(render-attr-map (merge ~tag-attrs ~attrs-sym))
~(end-tag)))
(build-string ~(str "<" tag (render-attr-map tag-attrs) ">")
~@(compile-seq [attrs-sym])
;; tail
~@(compile-seq content)
~(str "</" tag ">"))))))
(build-string
(if (map? ~attrs-sym)
~(if (container-tag? tag content)
`(build-string ~(str "<" tag)
(render-attr-map (merge ~tag-attrs ~attrs-sym))
">")
`(build-string ~(str "<" tag)
(render-attr-map (merge ~tag-attrs ~attrs-sym))
~(end-tag)))
(build-string ~(str "<" tag (render-attr-map tag-attrs) ">")
~@(compile-seq [attrs-sym])))
;; content and ending tag (when the above code did not emit an ending tag)
(when (or ~(boolean (container-tag? tag content))
(not (map? ~attrs-sym)))
(build-string ~@(compile-seq content)
~(str "</" tag ">")))))))

(defmethod compile-element :default
[element]
Expand Down

0 comments on commit 6fef3a6

Please sign in to comment.