Permalink
Browse files

Improve slurp performance by using native Java StringWriter and jio/copy

  • Loading branch information...
juergenhoetzel committed Oct 26, 2010
1 parent 3b9fed5 commit af1a5713cd485ba5f1db25c37906ebaf7d474b47
Showing with 3 additions and 7 deletions.
  1. +3 −7 src/clj/clojure/core.clj
View
@@ -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

0 comments on commit af1a571

Please sign in to comment.