Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve slurp performance by using native Java StringWriter and jio/copy
  • Loading branch information
juergenhoetzel committed Oct 26, 2010
1 parent 3b9fed5 commit af1a571
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/clj/clojure/core.clj
Expand Up @@ -5831,14 +5831,10 @@
{:added "1.0"}
([f & opts]
(let [opts (normalize-slurp-opts opts)
sb (StringBuilder.)]
sw (java.io.StringWriter.)]
(with-open [#^java.io.Reader r (apply jio/reader f opts)]
(loop [c (.read r)]
(if (neg? c)
(str sb)
(do
(.append sb (char c))
(recur (.read r)))))))))
(jio/copy r sw)
(str sw)))))

(defn spit
"Opposite of slurp. Opens f with writer, writes content, then
Expand Down

0 comments on commit af1a571

Please sign in to comment.